gencode-ai 0.2.0 → 0.3.0
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/dist/agent/agent.d.ts +9 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +37 -8
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +15 -9
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/Messages.js +1 -1
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/components/ModelSelector.d.ts +4 -3
- package/dist/cli/components/ModelSelector.d.ts.map +1 -1
- package/dist/cli/components/ModelSelector.js +54 -37
- package/dist/cli/components/ModelSelector.js.map +1 -1
- package/dist/cli/components/ProviderManager.d.ts +2 -2
- package/dist/cli/components/ProviderManager.d.ts.map +1 -1
- package/dist/cli/components/ProviderManager.js +137 -156
- package/dist/cli/components/ProviderManager.js.map +1 -1
- package/dist/cli/index.js +30 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/levels.d.ts +5 -5
- package/dist/config/levels.d.ts.map +1 -1
- package/dist/config/levels.js +20 -20
- package/dist/config/levels.js.map +1 -1
- package/dist/config/merger.js +1 -1
- package/dist/config/merger.js.map +1 -1
- package/dist/config/providers-config.d.ts +8 -5
- package/dist/config/providers-config.d.ts.map +1 -1
- package/dist/config/providers-config.js +19 -22
- package/dist/config/providers-config.js.map +1 -1
- package/dist/config/test-utils.d.ts +2 -2
- package/dist/config/test-utils.d.ts.map +1 -1
- package/dist/config/test-utils.js +4 -4
- package/dist/config/test-utils.js.map +1 -1
- package/dist/config/types.d.ts +23 -17
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +14 -14
- package/dist/config/types.js.map +1 -1
- package/dist/memory/memory-manager.d.ts +25 -12
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +241 -112
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/memory/test-utils.d.ts +1 -1
- package/dist/memory/test-utils.d.ts.map +1 -1
- package/dist/memory/test-utils.js +3 -3
- package/dist/memory/test-utils.js.map +1 -1
- package/dist/memory/types.d.ts +20 -10
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/types.js +13 -13
- package/dist/memory/types.js.map +1 -1
- package/dist/migration/migrate.d.ts +24 -0
- package/dist/migration/migrate.d.ts.map +1 -0
- package/dist/migration/migrate.js +164 -0
- package/dist/migration/migrate.js.map +1 -0
- package/dist/permissions/persistence.d.ts +2 -2
- package/dist/permissions/persistence.js +4 -4
- package/dist/permissions/persistence.js.map +1 -1
- package/dist/planning/plan-file.d.ts +1 -1
- package/dist/planning/plan-file.js +2 -2
- package/dist/planning/plan-file.js.map +1 -1
- package/dist/prompts/index.d.ts +5 -4
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +11 -8
- package/dist/prompts/index.js.map +1 -1
- package/dist/providers/anthropic.d.ts +2 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +7 -0
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/gemini.d.ts +2 -1
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +7 -0
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/index.d.ts +20 -10
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +48 -24
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai.d.ts +2 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +7 -0
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/registry.d.ts +48 -34
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +72 -88
- package/dist/providers/registry.js.map +1 -1
- package/dist/providers/store.d.ts +43 -17
- package/dist/providers/store.d.ts.map +1 -1
- package/dist/providers/store.js +112 -19
- package/dist/providers/store.js.map +1 -1
- package/dist/providers/types.d.ts +23 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/vertex-ai.d.ts +15 -7
- package/dist/providers/vertex-ai.d.ts.map +1 -1
- package/dist/providers/vertex-ai.js +46 -13
- package/dist/providers/vertex-ai.js.map +1 -1
- package/dist/session/types.js +1 -1
- package/dist/session/types.js.map +1 -1
- package/docs/config-system-comparison.md +50 -50
- package/docs/cost-tracking-comparison.md +2 -2
- package/docs/memory-system.md +124 -31
- package/docs/permissions.md +2 -2
- package/docs/proposals/0006-memory-system.md +4 -4
- package/docs/proposals/0008-checkpointing.md +109 -2
- package/docs/proposals/0011-custom-commands.md +2 -1
- package/docs/proposals/0021-skills-system.md +2 -1
- package/docs/proposals/0023-permission-enhancements.md +2 -2
- package/docs/proposals/0033-enterprise-deployment.md +1 -1
- package/docs/proposals/0041-configuration-system.md +17 -19
- package/docs/proposals/0042-prompt-optimization.md +17 -9
- package/docs/proposals/README.md +5 -5
- package/docs/providers.md +94 -9
- package/package.json +3 -2
- package/scripts/migrate.ts +449 -0
- package/src/agent/agent.ts +51 -9
- package/src/agent/types.ts +5 -1
- package/src/cli/components/App.tsx +17 -8
- package/src/cli/components/Messages.tsx +1 -1
- package/src/cli/components/ModelSelector.tsx +62 -43
- package/src/cli/components/ProviderManager.tsx +278 -323
- package/src/cli/index.tsx +36 -17
- package/src/config/index.ts +5 -3
- package/src/config/levels.test.ts +22 -22
- package/src/config/levels.ts +22 -22
- package/src/config/loader.test.ts +14 -14
- package/src/config/manager.test.ts +19 -19
- package/src/config/merger.test.ts +23 -23
- package/src/config/merger.ts +1 -1
- package/src/config/providers-config.ts +23 -21
- package/src/config/test-utils.ts +6 -6
- package/src/config/types.ts +30 -20
- package/src/memory/memory-manager.test.ts +242 -24
- package/src/memory/memory-manager.ts +270 -141
- package/src/memory/test-utils.ts +4 -4
- package/src/memory/types.ts +28 -17
- package/src/permissions/persistence.ts +4 -4
- package/src/planning/plan-file.ts +2 -2
- package/src/prompts/index.ts +13 -9
- package/src/providers/anthropic.ts +9 -0
- package/src/providers/gemini.ts +9 -0
- package/src/providers/index.ts +76 -33
- package/src/providers/openai.ts +9 -0
- package/src/providers/registry.ts +116 -111
- package/src/providers/store.ts +130 -28
- package/src/providers/types.ts +33 -1
- package/src/providers/vertex-ai.ts +49 -13
- package/src/session/types.ts +1 -1
package/src/memory/types.ts
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Memory System Types
|
|
3
3
|
*
|
|
4
4
|
* Hierarchical memory loading compatible with Claude Code:
|
|
5
|
-
* At each level, both .
|
|
5
|
+
* At each level, both .gen and .claude are loaded and merged (gen has higher priority).
|
|
6
6
|
*
|
|
7
7
|
* Levels:
|
|
8
8
|
* - Enterprise: System-wide managed memory (enforced)
|
|
9
|
-
* - User: ~/.
|
|
10
|
-
* - User Rules: ~/.
|
|
11
|
-
* - Extra:
|
|
12
|
-
* - Project: ./
|
|
13
|
-
* - Project Rules: .
|
|
9
|
+
* - User: ~/.gen/ + ~/.claude/ (both loaded, gen content appears later)
|
|
10
|
+
* - User Rules: ~/.gen/rules/ + ~/.claude/rules/
|
|
11
|
+
* - Extra: GEN_CONFIG_DIRS directories
|
|
12
|
+
* - Project: ./GEN.md, .gen/, ./CLAUDE.md, .claude/ (recursive upward search)
|
|
13
|
+
* - Project Rules: .gen/rules/ + .claude/rules/
|
|
14
14
|
* - Local: *.local.md files (gitignored)
|
|
15
15
|
*/
|
|
16
16
|
|
|
@@ -23,7 +23,16 @@ export type MemoryLevel =
|
|
|
23
23
|
| 'project-rules'
|
|
24
24
|
| 'local';
|
|
25
25
|
|
|
26
|
-
export type MemoryNamespace = '
|
|
26
|
+
export type MemoryNamespace = 'gen' | 'claude' | 'extra';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Memory merge strategy - how to combine CLAUDE.md and GEN.md at each level
|
|
30
|
+
* - fallback: Load GEN.md if exists, else CLAUDE.md (reduces context, default)
|
|
31
|
+
* - both: Load both CLAUDE.md and GEN.md (current behavior, max context)
|
|
32
|
+
* - gen-only: Only load .gen/GEN.md files
|
|
33
|
+
* - claude-only: Only load .claude/CLAUDE.md files
|
|
34
|
+
*/
|
|
35
|
+
export type MemoryMergeStrategy = 'fallback' | 'both' | 'gen-only' | 'claude-only';
|
|
27
36
|
|
|
28
37
|
export interface MemoryFile {
|
|
29
38
|
path: string;
|
|
@@ -46,9 +55,9 @@ export interface MemoryRule {
|
|
|
46
55
|
|
|
47
56
|
export interface MemoryConfig {
|
|
48
57
|
// GenCode file names (higher priority)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
genFilename: string;
|
|
59
|
+
genLocalFilename: string;
|
|
60
|
+
genDir: string;
|
|
52
61
|
|
|
53
62
|
// Claude file names (lower priority, loaded first)
|
|
54
63
|
claudeFilename: string;
|
|
@@ -64,9 +73,9 @@ export interface MemoryConfig {
|
|
|
64
73
|
|
|
65
74
|
export const DEFAULT_MEMORY_CONFIG: MemoryConfig = {
|
|
66
75
|
// GenCode
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
genFilename: 'GEN.md',
|
|
77
|
+
genLocalFilename: 'GEN.local.md',
|
|
78
|
+
genDir: '.gen',
|
|
70
79
|
|
|
71
80
|
// Claude
|
|
72
81
|
claudeFilename: 'CLAUDE.md',
|
|
@@ -82,13 +91,13 @@ export const DEFAULT_MEMORY_CONFIG: MemoryConfig = {
|
|
|
82
91
|
|
|
83
92
|
// Legacy compatibility
|
|
84
93
|
export const LEGACY_MEMORY_CONFIG = {
|
|
85
|
-
primaryFilename: '
|
|
94
|
+
primaryFilename: 'GEN.md',
|
|
86
95
|
fallbackFilename: 'CLAUDE.md',
|
|
87
|
-
localFilename: '
|
|
96
|
+
localFilename: 'GEN.local.md',
|
|
88
97
|
localFallbackFilename: 'CLAUDE.local.md',
|
|
89
|
-
primaryUserDir: '.
|
|
98
|
+
primaryUserDir: '.gen',
|
|
90
99
|
fallbackUserDir: '.claude',
|
|
91
|
-
primaryLocalDir: '.
|
|
100
|
+
primaryLocalDir: '.gen',
|
|
92
101
|
fallbackLocalDir: '.claude',
|
|
93
102
|
rulesDir: 'rules',
|
|
94
103
|
maxFileSize: 100 * 1024,
|
|
@@ -103,6 +112,7 @@ export interface LoadedMemory {
|
|
|
103
112
|
context: string;
|
|
104
113
|
errors: string[];
|
|
105
114
|
sources: MemorySource[]; // For debugging
|
|
115
|
+
skippedFiles: string[]; // Files skipped due to merge strategy
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
export interface MemorySource {
|
|
@@ -116,4 +126,5 @@ export interface MemorySource {
|
|
|
116
126
|
export interface MemoryLoadOptions {
|
|
117
127
|
cwd: string;
|
|
118
128
|
currentFile?: string; // For activating path-scoped rules
|
|
129
|
+
strategy?: MemoryMergeStrategy; // How to merge CLAUDE.md and AGENT.md (default: 'fallback')
|
|
119
130
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Permission Persistence - Store and load permission rules
|
|
3
3
|
*
|
|
4
4
|
* Handles persistent storage of permission rules at:
|
|
5
|
-
* - Global: ~/.
|
|
6
|
-
* - Project: .
|
|
5
|
+
* - Global: ~/.gen/permissions.json
|
|
6
|
+
* - Project: .gen/permissions.json
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as fs from 'fs/promises';
|
|
@@ -21,7 +21,7 @@ import { parsePatternString } from './prompt-matcher.js';
|
|
|
21
21
|
|
|
22
22
|
const PERMISSIONS_VERSION = 1;
|
|
23
23
|
const PERMISSIONS_FILE = 'permissions.json';
|
|
24
|
-
const GLOBAL_DIR = path.join(os.homedir(), '.
|
|
24
|
+
const GLOBAL_DIR = path.join(os.homedir(), '.gen');
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Permission Persistence Manager
|
|
@@ -32,7 +32,7 @@ export class PermissionPersistence {
|
|
|
32
32
|
|
|
33
33
|
constructor(projectPath?: string) {
|
|
34
34
|
this.globalDir = GLOBAL_DIR;
|
|
35
|
-
this.projectDir = projectPath ? path.join(projectPath, '.
|
|
35
|
+
this.projectDir = projectPath ? path.join(projectPath, '.gen') : null;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plan File Utilities
|
|
3
3
|
*
|
|
4
|
-
* Manages plan files stored in .
|
|
4
|
+
* Manages plan files stored in .gen/plans/ directory.
|
|
5
5
|
* Generates unique filenames with timestamps and slugs.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ import type { PlanFile } from './types.js';
|
|
|
14
14
|
// Constants
|
|
15
15
|
// ============================================================================
|
|
16
16
|
|
|
17
|
-
const PLANS_DIR = '.
|
|
17
|
+
const PLANS_DIR = '.gen/plans';
|
|
18
18
|
const PLAN_FILE_EXTENSION = '.md';
|
|
19
19
|
|
|
20
20
|
// Word lists for generating memorable names (like Claude Code)
|
package/src/prompts/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ import * as os from 'os';
|
|
|
14
14
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
15
|
|
|
16
16
|
// Path to providers.json config
|
|
17
|
-
const PROVIDERS_CONFIG_PATH = join(homedir(), '.
|
|
17
|
+
const PROVIDERS_CONFIG_PATH = join(homedir(), '.gen', 'providers.json');
|
|
18
18
|
|
|
19
19
|
// Resolve prompts directory - check both src and dist locations
|
|
20
20
|
function getPromptsDir(): string {
|
|
@@ -33,7 +33,7 @@ const promptsDir = getPromptsDir();
|
|
|
33
33
|
export type ProviderType = 'anthropic' | 'openai' | 'gemini' | 'generic';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Providers config structure from ~/.
|
|
36
|
+
* Providers config structure from ~/.gen/providers.json
|
|
37
37
|
*/
|
|
38
38
|
interface ProvidersConfig {
|
|
39
39
|
connections: Record<string, unknown>;
|
|
@@ -41,7 +41,7 @@ interface ProvidersConfig {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Load providers config from ~/.
|
|
44
|
+
* Load providers config from ~/.gen/providers.json
|
|
45
45
|
*/
|
|
46
46
|
function loadProvidersConfig(): ProvidersConfig | null {
|
|
47
47
|
try {
|
|
@@ -57,7 +57,7 @@ function loadProvidersConfig(): ProvidersConfig | null {
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Look up which provider owns a given model ID
|
|
60
|
-
* Searches through ~/.
|
|
60
|
+
* Searches through ~/.gen/providers.json to find the provider
|
|
61
61
|
*
|
|
62
62
|
* @param model - The model ID (e.g., "claude-sonnet-4-5@20250929")
|
|
63
63
|
* @returns The provider name (e.g., "anthropic") or null if not found
|
|
@@ -80,9 +80,13 @@ export function getProviderForModel(model: string): string | null {
|
|
|
80
80
|
/**
|
|
81
81
|
* Map provider names to prompt types
|
|
82
82
|
* Falls back to 'generic' for unknown providers
|
|
83
|
+
* Handles both "provider" and "provider:authMethod" formats
|
|
83
84
|
*/
|
|
84
85
|
export function mapProviderToPromptType(provider: string): ProviderType {
|
|
85
|
-
|
|
86
|
+
// Extract provider prefix (e.g., "gemini:api_key" → "gemini")
|
|
87
|
+
const providerPrefix = provider.split(':')[0];
|
|
88
|
+
|
|
89
|
+
switch (providerPrefix) {
|
|
86
90
|
case 'anthropic':
|
|
87
91
|
return 'anthropic';
|
|
88
92
|
case 'openai':
|
|
@@ -200,7 +204,7 @@ export function buildSystemPrompt(
|
|
|
200
204
|
|
|
201
205
|
/**
|
|
202
206
|
* Format memory context for injection into system prompt
|
|
203
|
-
* Uses <claudeMd> tag for Claude
|
|
207
|
+
* Uses <claudeMd> tag for optimal compatibility with Claude models
|
|
204
208
|
*/
|
|
205
209
|
export function formatMemoryContext(memoryContext: string): string {
|
|
206
210
|
if (!memoryContext) {
|
|
@@ -240,7 +244,7 @@ export function buildSystemPromptWithMemory(
|
|
|
240
244
|
* Flow: model → provider (from providers.json) → prompt
|
|
241
245
|
*
|
|
242
246
|
* This is the recommended way to build system prompts as it automatically
|
|
243
|
-
* looks up the provider for the given model from ~/.
|
|
247
|
+
* looks up the provider for the given model from ~/.gen/providers.json
|
|
244
248
|
*
|
|
245
249
|
* @param model - The model ID (e.g., "claude-sonnet-4-5@20250929")
|
|
246
250
|
* @param cwd - Current working directory
|
|
@@ -261,10 +265,10 @@ export function buildSystemPromptForModel(
|
|
|
261
265
|
|
|
262
266
|
/**
|
|
263
267
|
* Debug utility to verify prompt loading at runtime
|
|
264
|
-
* Set
|
|
268
|
+
* Set GEN_DEBUG_PROMPTS=1 for summary, GEN_DEBUG_PROMPTS=2 for full content
|
|
265
269
|
*/
|
|
266
270
|
export function debugPromptLoading(model: string, fallbackProvider?: string): void {
|
|
267
|
-
const debugLevel = process.env.
|
|
271
|
+
const debugLevel = process.env.GEN_DEBUG_PROMPTS;
|
|
268
272
|
if (!debugLevel || debugLevel === '0') {
|
|
269
273
|
return;
|
|
270
274
|
}
|
|
@@ -7,6 +7,7 @@ import Anthropic from '@anthropic-ai/sdk';
|
|
|
7
7
|
import { calculateCost } from '../pricing/calculator.js';
|
|
8
8
|
import type {
|
|
9
9
|
LLMProvider,
|
|
10
|
+
ProviderClassMeta,
|
|
10
11
|
CompletionOptions,
|
|
11
12
|
CompletionResponse,
|
|
12
13
|
StreamChunk,
|
|
@@ -23,6 +24,14 @@ type AnthropicTool = Anthropic.Tool;
|
|
|
23
24
|
type AnthropicContent = Anthropic.ContentBlockParam;
|
|
24
25
|
|
|
25
26
|
export class AnthropicProvider implements LLMProvider {
|
|
27
|
+
static readonly meta: ProviderClassMeta = {
|
|
28
|
+
provider: 'anthropic',
|
|
29
|
+
authMethod: 'api_key',
|
|
30
|
+
envVars: ['ANTHROPIC_API_KEY'],
|
|
31
|
+
displayName: 'Direct API',
|
|
32
|
+
description: 'Direct API access',
|
|
33
|
+
};
|
|
34
|
+
|
|
26
35
|
readonly name = 'anthropic';
|
|
27
36
|
private client: Anthropic;
|
|
28
37
|
|
package/src/providers/gemini.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { Content, Part, Tool, GenerateContentResult } from '@google/generat
|
|
|
8
8
|
import { calculateCost } from '../pricing/calculator.js';
|
|
9
9
|
import type {
|
|
10
10
|
LLMProvider,
|
|
11
|
+
ProviderClassMeta,
|
|
11
12
|
CompletionOptions,
|
|
12
13
|
CompletionResponse,
|
|
13
14
|
StreamChunk,
|
|
@@ -21,6 +22,14 @@ import type {
|
|
|
21
22
|
} from './types.js';
|
|
22
23
|
|
|
23
24
|
export class GeminiProvider implements LLMProvider {
|
|
25
|
+
static readonly meta: ProviderClassMeta = {
|
|
26
|
+
provider: 'gemini',
|
|
27
|
+
authMethod: 'api_key',
|
|
28
|
+
envVars: ['GOOGLE_API_KEY', 'GEMINI_API_KEY'],
|
|
29
|
+
displayName: 'Direct API',
|
|
30
|
+
description: 'Direct API access',
|
|
31
|
+
};
|
|
32
|
+
|
|
24
33
|
readonly name = 'gemini';
|
|
25
34
|
private client: GoogleGenerativeAI;
|
|
26
35
|
private apiKey: string;
|
package/src/providers/index.ts
CHANGED
|
@@ -6,56 +6,80 @@ export * from './types.js';
|
|
|
6
6
|
export { OpenAIProvider } from './openai.js';
|
|
7
7
|
export { AnthropicProvider } from './anthropic.js';
|
|
8
8
|
export { GeminiProvider } from './gemini.js';
|
|
9
|
-
export {
|
|
9
|
+
export { AnthropicVertexProvider } from './vertex-ai.js';
|
|
10
10
|
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
LLMProvider,
|
|
13
|
+
Provider,
|
|
14
|
+
AuthMethod,
|
|
15
|
+
OpenAIConfig,
|
|
16
|
+
AnthropicConfig,
|
|
17
|
+
GeminiConfig,
|
|
18
|
+
VertexAIConfig,
|
|
19
|
+
} from './types.js';
|
|
12
20
|
import { OpenAIProvider } from './openai.js';
|
|
13
21
|
import { AnthropicProvider } from './anthropic.js';
|
|
14
22
|
import { GeminiProvider } from './gemini.js';
|
|
15
|
-
import {
|
|
23
|
+
import { AnthropicVertexProvider } from './vertex-ai.js';
|
|
24
|
+
|
|
25
|
+
// Legacy type alias for backward compatibility
|
|
26
|
+
/** @deprecated Use Provider instead */
|
|
27
|
+
export type ProviderName = Provider;
|
|
16
28
|
|
|
17
|
-
export type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'vertex-ai';
|
|
18
29
|
export type ProviderConfigMap = {
|
|
19
30
|
openai: OpenAIConfig;
|
|
20
31
|
anthropic: AnthropicConfig;
|
|
21
32
|
gemini: GeminiConfig;
|
|
22
|
-
'vertex-ai': VertexAIConfig;
|
|
23
33
|
};
|
|
24
34
|
|
|
25
|
-
export interface CreateProviderOptions
|
|
26
|
-
provider:
|
|
27
|
-
|
|
35
|
+
export interface CreateProviderOptions {
|
|
36
|
+
provider: Provider;
|
|
37
|
+
authMethod?: AuthMethod;
|
|
38
|
+
config?: OpenAIConfig | AnthropicConfig | GeminiConfig | VertexAIConfig;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
/**
|
|
31
|
-
* Create a provider instance by
|
|
42
|
+
* Create a provider instance by provider and auth method
|
|
43
|
+
* If authMethod is not provided, defaults to 'api_key'
|
|
32
44
|
*/
|
|
33
45
|
export function createProvider(options: CreateProviderOptions): LLMProvider {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
const { provider, authMethod = 'api_key', config } = options;
|
|
47
|
+
|
|
48
|
+
// Map provider + authMethod to the correct implementation
|
|
49
|
+
if (provider === 'anthropic') {
|
|
50
|
+
if (authMethod === 'vertex') {
|
|
51
|
+
return new AnthropicVertexProvider(config as VertexAIConfig);
|
|
52
|
+
} else if (authMethod === 'api_key') {
|
|
53
|
+
return new AnthropicProvider(config as AnthropicConfig);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`Unsupported auth method for anthropic: ${authMethod}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (provider === 'openai') {
|
|
59
|
+
if (authMethod === 'api_key') {
|
|
60
|
+
return new OpenAIProvider(config as OpenAIConfig);
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`Unsupported auth method for openai: ${authMethod}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (provider === 'gemini') {
|
|
66
|
+
if (authMethod === 'api_key') {
|
|
67
|
+
return new GeminiProvider(config as GeminiConfig);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`Unsupported auth method for gemini: ${authMethod}`);
|
|
45
70
|
}
|
|
71
|
+
|
|
72
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
46
73
|
}
|
|
47
74
|
|
|
48
75
|
/**
|
|
49
76
|
* Infer provider from model name
|
|
77
|
+
* Note: This only returns the provider, not the auth method
|
|
78
|
+
* For Vertex AI models (claude-*@version), this returns 'anthropic'
|
|
50
79
|
*/
|
|
51
|
-
export function inferProvider(model: string):
|
|
80
|
+
export function inferProvider(model: string): Provider {
|
|
52
81
|
const modelLower = model.toLowerCase();
|
|
53
82
|
|
|
54
|
-
// Vertex AI models (Claude models with @ version suffix like claude-sonnet-4-5@20250929)
|
|
55
|
-
if (modelLower.includes('claude') && modelLower.includes('@')) {
|
|
56
|
-
return 'vertex-ai';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
83
|
// OpenAI models
|
|
60
84
|
if (
|
|
61
85
|
modelLower.includes('gpt') ||
|
|
@@ -68,7 +92,7 @@ export function inferProvider(model: string): ProviderName {
|
|
|
68
92
|
return 'openai';
|
|
69
93
|
}
|
|
70
94
|
|
|
71
|
-
// Anthropic models
|
|
95
|
+
// Anthropic models (including Vertex AI format with @)
|
|
72
96
|
if (modelLower.includes('claude')) {
|
|
73
97
|
return 'anthropic';
|
|
74
98
|
}
|
|
@@ -82,10 +106,29 @@ export function inferProvider(model: string): ProviderName {
|
|
|
82
106
|
return 'openai';
|
|
83
107
|
}
|
|
84
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Infer auth method from model name
|
|
111
|
+
* Returns undefined if auth method cannot be inferred
|
|
112
|
+
*/
|
|
113
|
+
export function inferAuthMethod(model: string): AuthMethod | undefined {
|
|
114
|
+
const modelLower = model.toLowerCase();
|
|
115
|
+
|
|
116
|
+
// Vertex AI models (Claude models with @ version suffix like claude-sonnet-4-5@20250929)
|
|
117
|
+
if (modelLower.includes('claude') && modelLower.includes('@')) {
|
|
118
|
+
return 'vertex';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// For other models, we can't reliably infer auth method
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
85
125
|
/**
|
|
86
126
|
* Common model aliases
|
|
87
127
|
*/
|
|
88
|
-
export const ModelAliases: Record<
|
|
128
|
+
export const ModelAliases: Record<
|
|
129
|
+
string,
|
|
130
|
+
{ provider: Provider; authMethod?: AuthMethod; model: string }
|
|
131
|
+
> = {
|
|
89
132
|
// OpenAI
|
|
90
133
|
'gpt-4o': { provider: 'openai', model: 'gpt-4o' },
|
|
91
134
|
'gpt-4o-mini': { provider: 'openai', model: 'gpt-4o-mini' },
|
|
@@ -94,7 +137,7 @@ export const ModelAliases: Record<string, { provider: ProviderName; model: strin
|
|
|
94
137
|
'o1-mini': { provider: 'openai', model: 'o1-mini' },
|
|
95
138
|
'o3-mini': { provider: 'openai', model: 'o3-mini' },
|
|
96
139
|
|
|
97
|
-
// Anthropic
|
|
140
|
+
// Anthropic (Direct API)
|
|
98
141
|
'claude-opus': { provider: 'anthropic', model: 'claude-opus-4-5-20251101' },
|
|
99
142
|
'claude-sonnet': { provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
100
143
|
'claude-haiku': { provider: 'anthropic', model: 'claude-haiku-4-20250514' },
|
|
@@ -105,8 +148,8 @@ export const ModelAliases: Record<string, { provider: ProviderName; model: strin
|
|
|
105
148
|
'gemini-1.5-pro': { provider: 'gemini', model: 'gemini-1.5-pro' },
|
|
106
149
|
'gemini-1.5-flash': { provider: 'gemini', model: 'gemini-1.5-flash' },
|
|
107
150
|
|
|
108
|
-
// Vertex AI
|
|
109
|
-
'vertex-sonnet': { provider: 'vertex
|
|
110
|
-
'vertex-haiku': { provider: 'vertex
|
|
111
|
-
'vertex-opus': { provider: 'vertex
|
|
151
|
+
// Anthropic via Vertex AI
|
|
152
|
+
'vertex-sonnet': { provider: 'anthropic', authMethod: 'vertex', model: 'claude-sonnet-4-5@20250929' },
|
|
153
|
+
'vertex-haiku': { provider: 'anthropic', authMethod: 'vertex', model: 'claude-haiku-4-5@20251001' },
|
|
154
|
+
'vertex-opus': { provider: 'anthropic', authMethod: 'vertex', model: 'claude-opus-4-1@20250805' },
|
|
112
155
|
};
|
package/src/providers/openai.ts
CHANGED
|
@@ -7,6 +7,7 @@ import OpenAI from 'openai';
|
|
|
7
7
|
import { calculateCost } from '../pricing/calculator.js';
|
|
8
8
|
import type {
|
|
9
9
|
LLMProvider,
|
|
10
|
+
ProviderClassMeta,
|
|
10
11
|
CompletionOptions,
|
|
11
12
|
CompletionResponse,
|
|
12
13
|
StreamChunk,
|
|
@@ -22,6 +23,14 @@ type OpenAIMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
|
22
23
|
type OpenAITool = OpenAI.Chat.Completions.ChatCompletionTool;
|
|
23
24
|
|
|
24
25
|
export class OpenAIProvider implements LLMProvider {
|
|
26
|
+
static readonly meta: ProviderClassMeta = {
|
|
27
|
+
provider: 'openai',
|
|
28
|
+
authMethod: 'api_key',
|
|
29
|
+
envVars: ['OPENAI_API_KEY'],
|
|
30
|
+
displayName: 'Direct API',
|
|
31
|
+
description: 'Direct API access',
|
|
32
|
+
};
|
|
33
|
+
|
|
25
34
|
readonly name = 'openai';
|
|
26
35
|
private client: OpenAI;
|
|
27
36
|
|