@compilr-dev/sdk 0.1.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/LICENSE +21 -0
- package/dist/agent.d.ts +8 -0
- package/dist/agent.js +220 -0
- package/dist/config.d.ts +227 -0
- package/dist/config.js +4 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +99 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.js +11 -0
- package/dist/models/model-registry.d.ts +118 -0
- package/dist/models/model-registry.js +621 -0
- package/dist/models/model-tiers.d.ts +36 -0
- package/dist/models/model-tiers.js +105 -0
- package/dist/models/providers.d.ts +90 -0
- package/dist/models/providers.js +295 -0
- package/dist/models/types.d.ts +28 -0
- package/dist/models/types.js +30 -0
- package/dist/models.d.ts +21 -0
- package/dist/models.js +73 -0
- package/dist/presets/coding.d.ts +21 -0
- package/dist/presets/coding.js +61 -0
- package/dist/presets/index.d.ts +11 -0
- package/dist/presets/index.js +32 -0
- package/dist/presets/read-only.d.ts +8 -0
- package/dist/presets/read-only.js +44 -0
- package/dist/presets/types.d.ts +30 -0
- package/dist/presets/types.js +4 -0
- package/dist/provider.d.ts +28 -0
- package/dist/provider.js +88 -0
- package/dist/team.d.ts +10 -0
- package/dist/team.js +168 -0
- package/dist/tools.d.ts +18 -0
- package/dist/tools.js +95 -0
- package/package.json +70 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coding preset — batteries-included for software development
|
|
3
|
+
*/
|
|
4
|
+
import { readFileTool, writeFileTool, editTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, todoWriteTool, todoReadTool, webFetchTool, suggestTool, } from '@compilr-dev/agents';
|
|
5
|
+
import { allCodingTools, unifiedTools } from '@compilr-dev/agents-coding';
|
|
6
|
+
const CODING_SYSTEM_PROMPT = `You are a skilled software engineer. You help users with coding tasks including:
|
|
7
|
+
- Writing, reviewing, and debugging code
|
|
8
|
+
- Understanding codebases and architecture
|
|
9
|
+
- Running tests, builds, and other development commands
|
|
10
|
+
- Git operations and version control workflows
|
|
11
|
+
- Code analysis and refactoring
|
|
12
|
+
|
|
13
|
+
Guidelines:
|
|
14
|
+
- Read files before modifying them to understand existing code
|
|
15
|
+
- Prefer editing existing files over creating new ones
|
|
16
|
+
- Run tests after making changes to verify correctness
|
|
17
|
+
- Use git for version control (commit messages should be descriptive)
|
|
18
|
+
- Follow existing code style and patterns in the project
|
|
19
|
+
- Be concise in explanations, detailed in code`;
|
|
20
|
+
/**
|
|
21
|
+
* All file operation tools
|
|
22
|
+
*/
|
|
23
|
+
export const fileTools = [
|
|
24
|
+
readFileTool,
|
|
25
|
+
writeFileTool,
|
|
26
|
+
editTool,
|
|
27
|
+
grepTool,
|
|
28
|
+
globTool,
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* All shell tools
|
|
32
|
+
*/
|
|
33
|
+
export const shellTools = [bashTool, bashOutputTool, killShellTool];
|
|
34
|
+
/**
|
|
35
|
+
* Web tools
|
|
36
|
+
*/
|
|
37
|
+
export const webTools = [webFetchTool];
|
|
38
|
+
/**
|
|
39
|
+
* Utility tools (always included in coding preset)
|
|
40
|
+
*/
|
|
41
|
+
const utilityTools = [todoWriteTool, todoReadTool, suggestTool];
|
|
42
|
+
/**
|
|
43
|
+
* All coding preset tools combined
|
|
44
|
+
*/
|
|
45
|
+
const allPresetTools = [
|
|
46
|
+
...fileTools,
|
|
47
|
+
...shellTools,
|
|
48
|
+
...utilityTools,
|
|
49
|
+
...allCodingTools,
|
|
50
|
+
...unifiedTools,
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Coding preset — full development environment
|
|
54
|
+
*/
|
|
55
|
+
export const codingPreset = {
|
|
56
|
+
name: 'coding',
|
|
57
|
+
tools: allPresetTools,
|
|
58
|
+
systemPrompt: CODING_SYSTEM_PROMPT,
|
|
59
|
+
defaultPermissions: 'auto',
|
|
60
|
+
};
|
|
61
|
+
export { webTools as codingWebTools };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset registry
|
|
3
|
+
*/
|
|
4
|
+
export type { Preset } from './types.js';
|
|
5
|
+
export { codingPreset } from './coding.js';
|
|
6
|
+
export { readOnlyPreset } from './read-only.js';
|
|
7
|
+
import type { Preset } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a preset by name or return a custom preset object
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolvePreset(preset: 'coding' | 'read-only' | 'none' | Preset): Preset;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset registry
|
|
3
|
+
*/
|
|
4
|
+
export { codingPreset } from './coding.js';
|
|
5
|
+
export { readOnlyPreset } from './read-only.js';
|
|
6
|
+
import { codingPreset } from './coding.js';
|
|
7
|
+
import { readOnlyPreset } from './read-only.js';
|
|
8
|
+
/**
|
|
9
|
+
* Empty preset — no tools, minimal prompt
|
|
10
|
+
*/
|
|
11
|
+
const nonePreset = {
|
|
12
|
+
name: 'none',
|
|
13
|
+
tools: [],
|
|
14
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
15
|
+
defaultPermissions: 'auto',
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a preset by name or return a custom preset object
|
|
19
|
+
*/
|
|
20
|
+
export function resolvePreset(preset) {
|
|
21
|
+
if (typeof preset !== 'string') {
|
|
22
|
+
return preset;
|
|
23
|
+
}
|
|
24
|
+
switch (preset) {
|
|
25
|
+
case 'coding':
|
|
26
|
+
return codingPreset;
|
|
27
|
+
case 'read-only':
|
|
28
|
+
return readOnlyPreset;
|
|
29
|
+
case 'none':
|
|
30
|
+
return nonePreset;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only preset — exploration and analysis without side effects
|
|
3
|
+
*/
|
|
4
|
+
import { readFileTool, grepTool, globTool } from '@compilr-dev/agents';
|
|
5
|
+
import { gitStatusTool, gitDiffTool, gitLogTool, gitBlameTool, gitFileHistoryTool, findDefinitionTool, findReferencesTool, findTodosTool, } from '@compilr-dev/agents-coding';
|
|
6
|
+
import { unifiedTools } from '@compilr-dev/agents-coding';
|
|
7
|
+
const READ_ONLY_SYSTEM_PROMPT = `You are a code analysis assistant. You can read and explore code but cannot modify files or run commands.
|
|
8
|
+
|
|
9
|
+
Your capabilities:
|
|
10
|
+
- Read and search files (read_file, grep, glob)
|
|
11
|
+
- Explore git history (git_log, git_diff, git_status, git_blame)
|
|
12
|
+
- Analyze code structure (find_definition, find_references, find_todos)
|
|
13
|
+
- Multi-language code analysis (TypeScript, Python, Go)
|
|
14
|
+
|
|
15
|
+
Guidelines:
|
|
16
|
+
- Provide thorough analysis with specific file and line references
|
|
17
|
+
- Explain code patterns, architecture decisions, and potential issues
|
|
18
|
+
- When reviewing changes, focus on correctness, security, and maintainability`;
|
|
19
|
+
/**
|
|
20
|
+
* Read-only preset — code review, audits, exploration
|
|
21
|
+
*/
|
|
22
|
+
export const readOnlyPreset = {
|
|
23
|
+
name: 'read-only',
|
|
24
|
+
tools: [
|
|
25
|
+
// File reading
|
|
26
|
+
readFileTool,
|
|
27
|
+
grepTool,
|
|
28
|
+
globTool,
|
|
29
|
+
// Git (read-only operations)
|
|
30
|
+
gitStatusTool,
|
|
31
|
+
gitDiffTool,
|
|
32
|
+
gitLogTool,
|
|
33
|
+
gitBlameTool,
|
|
34
|
+
gitFileHistoryTool,
|
|
35
|
+
// Code search
|
|
36
|
+
findDefinitionTool,
|
|
37
|
+
findReferencesTool,
|
|
38
|
+
findTodosTool,
|
|
39
|
+
// Unified analysis
|
|
40
|
+
...unifiedTools,
|
|
41
|
+
],
|
|
42
|
+
systemPrompt: READ_ONLY_SYSTEM_PROMPT,
|
|
43
|
+
defaultPermissions: 'read-only',
|
|
44
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset interface for domain-specific agent configurations
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from '@compilr-dev/agents';
|
|
5
|
+
/**
|
|
6
|
+
* Loosened tool type that accepts any input generic.
|
|
7
|
+
* Required because Tool<T> is contravariant in T (handler parameter),
|
|
8
|
+
* so Tool<SpecificInput> is not assignable to Tool<object>.
|
|
9
|
+
*/
|
|
10
|
+
export interface AnyTool {
|
|
11
|
+
definition: ToolDefinition;
|
|
12
|
+
execute: (...args: never[]) => Promise<unknown>;
|
|
13
|
+
parallel?: boolean;
|
|
14
|
+
silent?: boolean;
|
|
15
|
+
readonly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A preset bundles tools, a system prompt, and default settings
|
|
19
|
+
* for a specific domain (coding, read-only, custom, etc.)
|
|
20
|
+
*/
|
|
21
|
+
export interface Preset {
|
|
22
|
+
/** Unique name for this preset */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Tools included in this preset */
|
|
25
|
+
tools: AnyTool[];
|
|
26
|
+
/** System prompt for the agent */
|
|
27
|
+
systemPrompt: string;
|
|
28
|
+
/** Default permission mode */
|
|
29
|
+
defaultPermissions?: 'auto' | 'read-only';
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider resolution — auto-detect from env vars or explicit config
|
|
3
|
+
*/
|
|
4
|
+
import type { LLMProvider } from '@compilr-dev/agents';
|
|
5
|
+
import type { ProviderType } from './config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Detect the provider type from environment variables.
|
|
8
|
+
* Returns the first match in priority order, or undefined if none found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function detectProviderFromEnv(): ProviderType | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Create an LLM provider from a provider type string.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createProviderFromType(type: ProviderType, options?: {
|
|
15
|
+
model?: string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
siteName?: string;
|
|
19
|
+
}): LLMProvider;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a provider from config.
|
|
22
|
+
* Priority: explicit LLMProvider > explicit type > env var auto-detection.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveProvider(config?: {
|
|
25
|
+
provider?: ProviderType | LLMProvider;
|
|
26
|
+
model?: string;
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
}): LLMProvider;
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider resolution — auto-detect from env vars or explicit config
|
|
3
|
+
*/
|
|
4
|
+
import { createClaudeProvider, createOpenAIProvider, createGeminiNativeProvider, createOllamaProvider, createTogetherProvider, createGroqProvider, createFireworksProvider, createPerplexityProvider, createOpenRouterProvider, } from '@compilr-dev/agents';
|
|
5
|
+
/**
|
|
6
|
+
* Environment variable → provider mapping (checked in priority order)
|
|
7
|
+
*/
|
|
8
|
+
const ENV_PROVIDER_MAP = [
|
|
9
|
+
{ envVar: 'ANTHROPIC_API_KEY', type: 'claude' },
|
|
10
|
+
{ envVar: 'OPENAI_API_KEY', type: 'openai' },
|
|
11
|
+
{ envVar: 'GOOGLE_AI_API_KEY', type: 'gemini' },
|
|
12
|
+
{ envVar: 'GEMINI_API_KEY', type: 'gemini' },
|
|
13
|
+
{ envVar: 'TOGETHER_API_KEY', type: 'together' },
|
|
14
|
+
{ envVar: 'GROQ_API_KEY', type: 'groq' },
|
|
15
|
+
{ envVar: 'FIREWORKS_API_KEY', type: 'fireworks' },
|
|
16
|
+
{ envVar: 'PERPLEXITY_API_KEY', type: 'perplexity' },
|
|
17
|
+
{ envVar: 'OPENROUTER_API_KEY', type: 'openrouter' },
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Detect the provider type from environment variables.
|
|
21
|
+
* Returns the first match in priority order, or undefined if none found.
|
|
22
|
+
*/
|
|
23
|
+
export function detectProviderFromEnv() {
|
|
24
|
+
for (const { envVar, type } of ENV_PROVIDER_MAP) {
|
|
25
|
+
if (process.env[envVar]) {
|
|
26
|
+
return type;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create an LLM provider from a provider type string.
|
|
33
|
+
*/
|
|
34
|
+
export function createProviderFromType(type, options) {
|
|
35
|
+
const { model, apiKey, baseUrl, siteName } = options ?? {};
|
|
36
|
+
switch (type) {
|
|
37
|
+
case 'claude':
|
|
38
|
+
return createClaudeProvider({ model, apiKey });
|
|
39
|
+
case 'openai':
|
|
40
|
+
return createOpenAIProvider({ model, apiKey });
|
|
41
|
+
case 'gemini':
|
|
42
|
+
return createGeminiNativeProvider({ model, apiKey });
|
|
43
|
+
case 'ollama':
|
|
44
|
+
return createOllamaProvider({ model, baseUrl });
|
|
45
|
+
case 'together':
|
|
46
|
+
return createTogetherProvider({ model, apiKey });
|
|
47
|
+
case 'groq':
|
|
48
|
+
return createGroqProvider({ model, apiKey });
|
|
49
|
+
case 'fireworks':
|
|
50
|
+
return createFireworksProvider({ model, apiKey });
|
|
51
|
+
case 'perplexity':
|
|
52
|
+
return createPerplexityProvider({ model, apiKey });
|
|
53
|
+
case 'openrouter':
|
|
54
|
+
return createOpenRouterProvider({ model, apiKey, siteName });
|
|
55
|
+
case 'custom':
|
|
56
|
+
// Custom endpoints use OpenAI-compatible format
|
|
57
|
+
return createOpenAIProvider({ model, apiKey });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a provider from config.
|
|
62
|
+
* Priority: explicit LLMProvider > explicit type > env var auto-detection.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveProvider(config) {
|
|
65
|
+
// Already an LLMProvider instance
|
|
66
|
+
if (config?.provider && typeof config.provider !== 'string') {
|
|
67
|
+
return config.provider;
|
|
68
|
+
}
|
|
69
|
+
// Explicit provider type
|
|
70
|
+
if (config?.provider && typeof config.provider === 'string') {
|
|
71
|
+
return createProviderFromType(config.provider, {
|
|
72
|
+
model: config.model,
|
|
73
|
+
apiKey: config.apiKey,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Auto-detect from env
|
|
77
|
+
const detected = detectProviderFromEnv();
|
|
78
|
+
if (detected) {
|
|
79
|
+
return createProviderFromType(detected, {
|
|
80
|
+
model: config?.model,
|
|
81
|
+
apiKey: config?.apiKey,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
throw new Error('No LLM provider configured. Either:\n' +
|
|
85
|
+
' 1. Set an API key env var (ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.)\n' +
|
|
86
|
+
' 2. Pass provider type: createCompilrAgent({ provider: "claude" })\n' +
|
|
87
|
+
' 3. Pass a provider instance: createCompilrAgent({ provider: myProvider })');
|
|
88
|
+
}
|
package/dist/team.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CompilrTeam — multi-agent coordinator
|
|
3
|
+
*
|
|
4
|
+
* v0.1: Sequential delegation — coordinator decides which agent handles each step
|
|
5
|
+
*/
|
|
6
|
+
import type { TeamConfig, CompilrTeam as ICompilrTeam } from './config.js';
|
|
7
|
+
/**
|
|
8
|
+
* Create a multi-agent team
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTeam(config: TeamConfig): ICompilrTeam;
|
package/dist/team.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CompilrTeam — multi-agent coordinator
|
|
3
|
+
*
|
|
4
|
+
* v0.1: Sequential delegation — coordinator decides which agent handles each step
|
|
5
|
+
*/
|
|
6
|
+
import { createCompilrAgent } from './agent.js';
|
|
7
|
+
/**
|
|
8
|
+
* Role-based system prompt fragments
|
|
9
|
+
*/
|
|
10
|
+
const ROLE_PROMPTS = {
|
|
11
|
+
architect: 'You are a software architect. Focus on high-level design, system architecture, ' +
|
|
12
|
+
'API contracts, and technical decisions. Break down complex tasks into smaller pieces.',
|
|
13
|
+
developer: 'You are a software developer. Focus on writing clean, correct, well-tested code. ' +
|
|
14
|
+
'Follow existing patterns and conventions in the codebase.',
|
|
15
|
+
tester: 'You are a QA engineer. Focus on writing tests, finding edge cases, and verifying ' +
|
|
16
|
+
'correctness. Run tests after changes and report failures clearly.',
|
|
17
|
+
reviewer: 'You are a code reviewer. Focus on code quality, security, performance, and ' +
|
|
18
|
+
'maintainability. Provide specific, actionable feedback.',
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Default coordinator prompt
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_COORDINATOR_PROMPT = 'You are a team coordinator. Analyze the task and delegate to the appropriate team member. ' +
|
|
24
|
+
'Synthesize their results into a coherent response.';
|
|
25
|
+
/**
|
|
26
|
+
* Merge usage info
|
|
27
|
+
*/
|
|
28
|
+
function mergeUsage(a, b) {
|
|
29
|
+
return {
|
|
30
|
+
inputTokens: a.inputTokens + b.inputTokens,
|
|
31
|
+
outputTokens: a.outputTokens + b.outputTokens,
|
|
32
|
+
totalTokens: a.totalTokens + b.totalTokens,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* CompilrTeam implementation — sequential delegation
|
|
37
|
+
*/
|
|
38
|
+
class CompilrTeamImpl {
|
|
39
|
+
agents = new Map();
|
|
40
|
+
coordinator;
|
|
41
|
+
agentConfigs;
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.agentConfigs = config.agents;
|
|
44
|
+
// Create coordinator agent
|
|
45
|
+
this.coordinator = createCompilrAgent({
|
|
46
|
+
...config,
|
|
47
|
+
systemPrompt: config.coordinatorPrompt ?? DEFAULT_COORDINATOR_PROMPT,
|
|
48
|
+
maxIterations: config.maxIterations ?? 10,
|
|
49
|
+
});
|
|
50
|
+
// Create team agents
|
|
51
|
+
for (const [name, agentConfig] of Object.entries(config.agents)) {
|
|
52
|
+
const systemPrompt = agentConfig.systemPrompt ?? (agentConfig.role ? ROLE_PROMPTS[agentConfig.role] : undefined);
|
|
53
|
+
const agent = createCompilrAgent({
|
|
54
|
+
provider: agentConfig.provider ?? config.provider,
|
|
55
|
+
model: agentConfig.model ?? config.model,
|
|
56
|
+
apiKey: config.apiKey,
|
|
57
|
+
preset: config.preset,
|
|
58
|
+
cwd: config.cwd,
|
|
59
|
+
systemPrompt: systemPrompt ?? false,
|
|
60
|
+
maxIterations: agentConfig.maxIterations ?? 30,
|
|
61
|
+
tools: agentConfig.toolFilter ? { filter: agentConfig.toolFilter } : config.tools,
|
|
62
|
+
hooks: config.hooks,
|
|
63
|
+
guardrails: config.guardrails,
|
|
64
|
+
});
|
|
65
|
+
this.agents.set(name, agent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async run(message, options) {
|
|
69
|
+
const agentResults = {};
|
|
70
|
+
let totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
71
|
+
// Simple sequential delegation: run each agent on the full task
|
|
72
|
+
// (v0.1 — future versions will use coordinator for routing)
|
|
73
|
+
for (const [name, agent] of this.agents) {
|
|
74
|
+
const role = this.agentConfigs[name].role ?? 'general';
|
|
75
|
+
const agentMessage = `[You are the ${role} on this team]\n\n${message}`;
|
|
76
|
+
options?.onEvent?.({
|
|
77
|
+
type: 'subagent_start',
|
|
78
|
+
name,
|
|
79
|
+
task: message,
|
|
80
|
+
});
|
|
81
|
+
const result = await agent.run(agentMessage, {
|
|
82
|
+
signal: options?.signal,
|
|
83
|
+
maxIterations: options?.maxIterations,
|
|
84
|
+
toolFilter: options?.toolFilter,
|
|
85
|
+
});
|
|
86
|
+
agentResults[name] = result;
|
|
87
|
+
totalUsage = mergeUsage(totalUsage, result.usage);
|
|
88
|
+
options?.onEvent?.({
|
|
89
|
+
type: 'subagent_end',
|
|
90
|
+
name,
|
|
91
|
+
result: {
|
|
92
|
+
response: result.response,
|
|
93
|
+
toolCalls: result.toolCalls.length,
|
|
94
|
+
iterations: result.iterations,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Synthesize results via coordinator
|
|
99
|
+
const synthesis = `Team results for task: "${message}"\n\n` +
|
|
100
|
+
Object.entries(agentResults)
|
|
101
|
+
.map(([name, r]) => `## ${name}\n${r.response}`)
|
|
102
|
+
.join('\n\n') +
|
|
103
|
+
'\n\nPlease synthesize these results into a final coherent response.';
|
|
104
|
+
const coordResult = await this.coordinator.run(synthesis, {
|
|
105
|
+
signal: options?.signal,
|
|
106
|
+
});
|
|
107
|
+
totalUsage = mergeUsage(totalUsage, coordResult.usage);
|
|
108
|
+
return {
|
|
109
|
+
response: coordResult.response,
|
|
110
|
+
agentResults,
|
|
111
|
+
usage: totalUsage,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async *stream(message, options) {
|
|
115
|
+
const events = [];
|
|
116
|
+
let notifyNewEvent;
|
|
117
|
+
const finished = { value: false };
|
|
118
|
+
const onEvent = (event) => {
|
|
119
|
+
events.push(event);
|
|
120
|
+
notifyNewEvent?.();
|
|
121
|
+
};
|
|
122
|
+
const markDone = () => {
|
|
123
|
+
finished.value = true;
|
|
124
|
+
notifyNewEvent?.();
|
|
125
|
+
};
|
|
126
|
+
const runPromise = this.run(message, {
|
|
127
|
+
...options,
|
|
128
|
+
onEvent: onEvent,
|
|
129
|
+
})
|
|
130
|
+
.then((result) => {
|
|
131
|
+
events.push({ type: 'team_done', response: result.response });
|
|
132
|
+
markDone();
|
|
133
|
+
})
|
|
134
|
+
.catch(markDone);
|
|
135
|
+
for (;;) {
|
|
136
|
+
if (events.length > 0) {
|
|
137
|
+
const event = events.shift();
|
|
138
|
+
if (event) {
|
|
139
|
+
yield event;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (finished.value) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
await new Promise((r) => {
|
|
147
|
+
notifyNewEvent = r;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
await runPromise;
|
|
152
|
+
}
|
|
153
|
+
getAgent(name) {
|
|
154
|
+
return this.agents.get(name);
|
|
155
|
+
}
|
|
156
|
+
abort() {
|
|
157
|
+
for (const agent of this.agents.values()) {
|
|
158
|
+
agent.abort();
|
|
159
|
+
}
|
|
160
|
+
this.coordinator.abort();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create a multi-agent team
|
|
165
|
+
*/
|
|
166
|
+
export function createTeam(config) {
|
|
167
|
+
return new CompilrTeamImpl(config);
|
|
168
|
+
}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool assembly — merge preset tools with user configuration
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolConfig } from './config.js';
|
|
5
|
+
import type { Preset, AnyTool } from './presets/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Assemble the final tool list from a preset and user config.
|
|
8
|
+
*
|
|
9
|
+
* Priority:
|
|
10
|
+
* 1. If `filter` is set, only include those tools from the preset
|
|
11
|
+
* 2. Otherwise, use boolean flags to toggle tool groups
|
|
12
|
+
* 3. Custom tools are always appended
|
|
13
|
+
*/
|
|
14
|
+
export declare function assembleTools(preset: Preset, toolConfig?: ToolConfig): AnyTool[];
|
|
15
|
+
/**
|
|
16
|
+
* Deduplicate tools by name (last wins)
|
|
17
|
+
*/
|
|
18
|
+
export declare function deduplicateTools(tools: AnyTool[]): AnyTool[];
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool assembly — merge preset tools with user configuration
|
|
3
|
+
*/
|
|
4
|
+
import { fileTools, shellTools, codingWebTools } from './presets/coding.js';
|
|
5
|
+
import { allCodingTools, unifiedTools } from '@compilr-dev/agents-coding';
|
|
6
|
+
/**
|
|
7
|
+
* Tool names for file operations
|
|
8
|
+
*/
|
|
9
|
+
const FILE_TOOL_NAMES = new Set(fileTools.map((t) => t.definition.name));
|
|
10
|
+
/**
|
|
11
|
+
* Tool names for shell operations
|
|
12
|
+
*/
|
|
13
|
+
const SHELL_TOOL_NAMES = new Set(shellTools.map((t) => t.definition.name));
|
|
14
|
+
/**
|
|
15
|
+
* Tool names for coding operations (git, runners, analysis)
|
|
16
|
+
*/
|
|
17
|
+
const CODING_TOOL_NAMES = new Set([...allCodingTools, ...unifiedTools].map((t) => t.definition.name));
|
|
18
|
+
/**
|
|
19
|
+
* Tool names for web operations
|
|
20
|
+
*/
|
|
21
|
+
const WEB_TOOL_NAMES = new Set(codingWebTools.map((t) => t.definition.name));
|
|
22
|
+
/**
|
|
23
|
+
* Assemble the final tool list from a preset and user config.
|
|
24
|
+
*
|
|
25
|
+
* Priority:
|
|
26
|
+
* 1. If `filter` is set, only include those tools from the preset
|
|
27
|
+
* 2. Otherwise, use boolean flags to toggle tool groups
|
|
28
|
+
* 3. Custom tools are always appended
|
|
29
|
+
*/
|
|
30
|
+
export function assembleTools(preset, toolConfig) {
|
|
31
|
+
const presetTools = preset.tools;
|
|
32
|
+
// If no config, return all preset tools
|
|
33
|
+
if (!toolConfig) {
|
|
34
|
+
return [...presetTools];
|
|
35
|
+
}
|
|
36
|
+
// If filter (allowlist) is specified, it takes precedence over flags
|
|
37
|
+
if (toolConfig.filter) {
|
|
38
|
+
const allowSet = new Set(toolConfig.filter);
|
|
39
|
+
const filtered = presetTools.filter((t) => allowSet.has(t.definition.name));
|
|
40
|
+
return [...filtered, ...(toolConfig.custom ?? [])];
|
|
41
|
+
}
|
|
42
|
+
// Apply boolean flags to filter preset tools
|
|
43
|
+
const result = [];
|
|
44
|
+
for (const tool of presetTools) {
|
|
45
|
+
const name = tool.definition.name;
|
|
46
|
+
if (FILE_TOOL_NAMES.has(name)) {
|
|
47
|
+
if (toolConfig.files !== false) {
|
|
48
|
+
result.push(tool);
|
|
49
|
+
}
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (SHELL_TOOL_NAMES.has(name)) {
|
|
53
|
+
if (toolConfig.shell !== false) {
|
|
54
|
+
result.push(tool);
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (CODING_TOOL_NAMES.has(name)) {
|
|
59
|
+
if (toolConfig.coding !== false) {
|
|
60
|
+
result.push(tool);
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (WEB_TOOL_NAMES.has(name)) {
|
|
65
|
+
if (toolConfig.web === true) {
|
|
66
|
+
result.push(tool);
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// Utility tools (todo, suggest) — always include
|
|
71
|
+
result.push(tool);
|
|
72
|
+
}
|
|
73
|
+
// If web tools were requested but not in the preset, add them
|
|
74
|
+
if (toolConfig.web === true) {
|
|
75
|
+
const hasWeb = result.some((t) => WEB_TOOL_NAMES.has(t.definition.name));
|
|
76
|
+
if (!hasWeb) {
|
|
77
|
+
result.push(...codingWebTools);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Append custom tools
|
|
81
|
+
if (toolConfig.custom) {
|
|
82
|
+
result.push(...toolConfig.custom);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Deduplicate tools by name (last wins)
|
|
88
|
+
*/
|
|
89
|
+
export function deduplicateTools(tools) {
|
|
90
|
+
const seen = new Map();
|
|
91
|
+
for (const tool of tools) {
|
|
92
|
+
seen.set(tool.definition.name, tool);
|
|
93
|
+
}
|
|
94
|
+
return [...seen.values()];
|
|
95
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@compilr-dev/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"clean": "rm -rf dist",
|
|
20
|
+
"lint": "eslint src/",
|
|
21
|
+
"lint:fix": "eslint src/ --fix",
|
|
22
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
23
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/compilr-dev/sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"ai",
|
|
36
|
+
"agents",
|
|
37
|
+
"sdk",
|
|
38
|
+
"llm",
|
|
39
|
+
"claude",
|
|
40
|
+
"openai",
|
|
41
|
+
"gemini",
|
|
42
|
+
"runtime",
|
|
43
|
+
"multi-llm",
|
|
44
|
+
"anthropic"
|
|
45
|
+
],
|
|
46
|
+
"author": "Carmelo Scozzola",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/compilr-dev/sdk/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/compilr-dev/sdk#readme",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@compilr-dev/agents": "^0.3.14",
|
|
57
|
+
"@compilr-dev/agents-coding": "^1.0.2"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@anthropic-ai/sdk": "^0.78.0",
|
|
61
|
+
"@eslint/js": "^9.39.1",
|
|
62
|
+
"@types/node": "^25.2.3",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
64
|
+
"eslint": "^9.39.1",
|
|
65
|
+
"prettier": "^3.7.1",
|
|
66
|
+
"typescript": "^5.3.0",
|
|
67
|
+
"typescript-eslint": "^8.48.0",
|
|
68
|
+
"vitest": "^4.0.18"
|
|
69
|
+
}
|
|
70
|
+
}
|