@intella/sdk 0.0.1
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/README.md +492 -0
- package/examples/claude-code/README.md +178 -0
- package/examples/claude-code/advanced-config.ts +55 -0
- package/examples/claude-code/basic-usage.ts +56 -0
- package/examples/claude-code/model-comparison.ts +50 -0
- package/examples/claude-code/orchestration.ts +70 -0
- package/examples/claude-code/streaming.ts +69 -0
- package/examples/claude-code/tsconfig.json +19 -0
- package/examples/code-extractor/README.md +77 -0
- package/examples/code-extractor/example.ts +145 -0
- package/examples/filesystem/basic-usage.ts +84 -0
- package/examples/integrated-task/README.md +68 -0
- package/examples/integrated-task/integrated-usage.ts +193 -0
- package/examples/integrated-task/simple-example.ts +51 -0
- package/examples/integrated-task/tsconfig.json +19 -0
- package/examples/sandbox/basic-usage.ts +173 -0
- package/package.json +56 -0
- package/src/agent-manager.ts +104 -0
- package/src/agents/base-agent.ts +166 -0
- package/src/agents/claude-agent.ts +77 -0
- package/src/agents/codex-agent.ts +72 -0
- package/src/agents/intella-lite-agent.ts +55 -0
- package/src/agents/opencode-agent.ts +45 -0
- package/src/filesystem/agentfs-provider.ts +328 -0
- package/src/filesystem/base-provider.ts +98 -0
- package/src/filesystem/index.ts +5 -0
- package/src/filesystem/memory-provider.ts +267 -0
- package/src/filesystem-manager.ts +213 -0
- package/src/index.ts +66 -0
- package/src/orchestrator.ts +177 -0
- package/src/sandbox/base-provider.ts +184 -0
- package/src/sandbox/daytona-provider.ts +462 -0
- package/src/sandbox/e2b-provider.ts +419 -0
- package/src/sandbox/modal-provider.ts +597 -0
- package/src/sandbox-manager.ts +175 -0
- package/src/sdk.ts +401 -0
- package/src/types.ts +451 -0
- package/src/utils/code-extractor.ts +194 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { generateText, streamText, type LanguageModel, type ModelMessage } from 'ai';
|
|
2
|
+
import type { AgentType, AgentConfig, TaskRequest, TaskResponse, StreamChunk, IAgent, MessageContent } from '../types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for all agents
|
|
6
|
+
* Provides common functionality using AI SDK v6
|
|
7
|
+
*/
|
|
8
|
+
export abstract class BaseAgent implements IAgent {
|
|
9
|
+
protected config: AgentConfig;
|
|
10
|
+
public readonly type: AgentType;
|
|
11
|
+
|
|
12
|
+
constructor(type: AgentType, config: AgentConfig = {}) {
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.config = { ...config };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the language model instance
|
|
19
|
+
* Must be implemented by subclasses
|
|
20
|
+
*/
|
|
21
|
+
abstract getModel(): LanguageModel | Promise<LanguageModel>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Execute a task and return the response
|
|
25
|
+
*/
|
|
26
|
+
async execute(request: TaskRequest): Promise<TaskResponse> {
|
|
27
|
+
const model = await Promise.resolve(this.getModel());
|
|
28
|
+
const messages = this.buildMessages(request);
|
|
29
|
+
|
|
30
|
+
const result = await generateText({
|
|
31
|
+
model,
|
|
32
|
+
messages,
|
|
33
|
+
temperature: request.temperature ?? this.config.temperature,
|
|
34
|
+
maxOutputTokens: request.maxTokens ?? this.config.maxTokens,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
text: result.text,
|
|
39
|
+
agentType: this.type,
|
|
40
|
+
metadata: {
|
|
41
|
+
usage: result.usage,
|
|
42
|
+
finishReason: result.finishReason,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Stream a task execution
|
|
49
|
+
*/
|
|
50
|
+
async *stream(request: TaskRequest): AsyncIterable<StreamChunk> {
|
|
51
|
+
const model = await Promise.resolve(this.getModel());
|
|
52
|
+
const messages = this.buildMessages(request);
|
|
53
|
+
|
|
54
|
+
const result = streamText({
|
|
55
|
+
model,
|
|
56
|
+
messages,
|
|
57
|
+
temperature: request.temperature ?? this.config.temperature,
|
|
58
|
+
maxOutputTokens: request.maxTokens ?? this.config.maxTokens,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
let fullText = '';
|
|
62
|
+
for await (const chunk of result.textStream) {
|
|
63
|
+
fullText += chunk;
|
|
64
|
+
yield {
|
|
65
|
+
text: chunk,
|
|
66
|
+
agentType: this.type,
|
|
67
|
+
isDone: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Final chunk to indicate completion
|
|
72
|
+
yield {
|
|
73
|
+
text: '',
|
|
74
|
+
agentType: this.type,
|
|
75
|
+
isDone: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Configure the agent
|
|
81
|
+
*/
|
|
82
|
+
configure(config: AgentConfig): void {
|
|
83
|
+
this.config = { ...this.config, ...config };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get current configuration
|
|
88
|
+
*/
|
|
89
|
+
getConfig(): AgentConfig {
|
|
90
|
+
return { ...this.config };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Convert TaskRequest content to AI SDK ModelMessage content format
|
|
95
|
+
*/
|
|
96
|
+
private convertContent(content: MessageContent): string | Array<{ type: 'text'; text: string } | { type: 'file'; data: string | Uint8Array | ArrayBuffer | Buffer | URL; filename?: string; mediaType: string }> {
|
|
97
|
+
// If content is a string, return as-is
|
|
98
|
+
if (typeof content === 'string') {
|
|
99
|
+
return content;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If content is an array, convert to AI SDK format
|
|
103
|
+
return content.map(part => {
|
|
104
|
+
if (part.type === 'text') {
|
|
105
|
+
return {
|
|
106
|
+
type: 'text' as const,
|
|
107
|
+
text: part.text,
|
|
108
|
+
};
|
|
109
|
+
} else if (part.type === 'file') {
|
|
110
|
+
return {
|
|
111
|
+
type: 'file' as const,
|
|
112
|
+
data: part.data,
|
|
113
|
+
filename: part.filename,
|
|
114
|
+
mediaType: part.mediaType,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Fallback for unknown types
|
|
118
|
+
return {
|
|
119
|
+
type: 'text' as const,
|
|
120
|
+
text: String(part),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Build messages array from request
|
|
127
|
+
*/
|
|
128
|
+
protected buildMessages(request: TaskRequest): ModelMessage[] {
|
|
129
|
+
const messages: ModelMessage[] = [];
|
|
130
|
+
|
|
131
|
+
// Add system prompt if provided
|
|
132
|
+
if (request.systemPrompt) {
|
|
133
|
+
messages.push({
|
|
134
|
+
role: 'system',
|
|
135
|
+
content: request.systemPrompt,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Add previous messages if provided
|
|
140
|
+
if (request.messages && request.messages.length > 0) {
|
|
141
|
+
for (const msg of request.messages) {
|
|
142
|
+
// Skip system messages in the messages array (they're handled separately)
|
|
143
|
+
if (msg.role === 'system') {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
messages.push({
|
|
148
|
+
role: msg.role,
|
|
149
|
+
content: this.convertContent(msg.content),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Add the main prompt as user message (only if not empty)
|
|
155
|
+
// If prompt is empty, the message is likely already in the messages array
|
|
156
|
+
if (request.prompt && request.prompt.trim()) {
|
|
157
|
+
messages.push({
|
|
158
|
+
role: 'user',
|
|
159
|
+
content: request.prompt,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return messages;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
|
+
import type { AgentConfig } from '../types.js';
|
|
3
|
+
import type { LanguageModel } from 'ai';
|
|
4
|
+
|
|
5
|
+
import { claudeCode, createClaudeCode, McpServerConfig } from 'ai-sdk-provider-claude-code';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Claude Agent
|
|
10
|
+
* Powered by Claude Code provider
|
|
11
|
+
*/
|
|
12
|
+
export class ClaudeAgent extends BaseAgent {
|
|
13
|
+
private modelInstance: LanguageModel | null = null;
|
|
14
|
+
|
|
15
|
+
constructor(config: AgentConfig = {}) {
|
|
16
|
+
super('claude', config);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get or create the language model instance
|
|
21
|
+
*
|
|
22
|
+
* Supports Claude Code provider options:
|
|
23
|
+
* - allowedTools, disallowedTools, mcpServers, permissionMode, maxTurns, cwd, verbose
|
|
24
|
+
* See: https://ai-sdk.dev/providers/community-providers/claude-code
|
|
25
|
+
*/
|
|
26
|
+
async getModel(): Promise<LanguageModel> {
|
|
27
|
+
if (!this.modelInstance) {
|
|
28
|
+
// Dynamic import to handle optional peer dependency
|
|
29
|
+
|
|
30
|
+
// Claude Code provider takes model ID as string parameter
|
|
31
|
+
// Uses CLI authentication (claude login) - API key not needed in code
|
|
32
|
+
// Model shortcuts: 'opus', 'sonnet', 'haiku'
|
|
33
|
+
const modelId = this.config.model || 'sonnet';
|
|
34
|
+
|
|
35
|
+
// Check if custom provider options are provided
|
|
36
|
+
const hasCustomOptions =
|
|
37
|
+
this.config.allowedTools ||
|
|
38
|
+
this.config.disallowedTools ||
|
|
39
|
+
this.config.mcpServers ||
|
|
40
|
+
this.config.permissionMode ||
|
|
41
|
+
this.config.maxTurns ||
|
|
42
|
+
this.config.cwd !== undefined ||
|
|
43
|
+
this.config.verbose !== undefined;
|
|
44
|
+
|
|
45
|
+
if (hasCustomOptions) {
|
|
46
|
+
// Create custom provider instance with options
|
|
47
|
+
const customProvider = createClaudeCode({
|
|
48
|
+
defaultSettings: {
|
|
49
|
+
allowedTools: this.config.allowedTools as string[] | undefined,
|
|
50
|
+
disallowedTools: this.config.disallowedTools as string[] | undefined,
|
|
51
|
+
mcpServers: this.config.mcpServers as Record<string, McpServerConfig> | undefined,
|
|
52
|
+
permissionMode: this.config.permissionMode as 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | undefined,
|
|
53
|
+
maxTurns: this.config.maxTurns as number | undefined,
|
|
54
|
+
cwd: this.config.cwd as string | undefined,
|
|
55
|
+
verbose: this.config.verbose as boolean | undefined,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
this.modelInstance = customProvider(modelId);
|
|
59
|
+
} else {
|
|
60
|
+
// Use default provider instance
|
|
61
|
+
this.modelInstance = claudeCode(modelId);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.modelInstance;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Override configure to reset model instance when config changes
|
|
70
|
+
*/
|
|
71
|
+
configure(config: AgentConfig): void {
|
|
72
|
+
super.configure(config);
|
|
73
|
+
// Reset model instance so it's recreated with new config
|
|
74
|
+
this.modelInstance = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
|
+
import type { AgentConfig } from '../types.js';
|
|
3
|
+
import type { LanguageModel } from 'ai';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Codex Agent
|
|
7
|
+
* Powered by Codex CLI provider
|
|
8
|
+
*/
|
|
9
|
+
export class CodexAgent extends BaseAgent {
|
|
10
|
+
private modelInstance: LanguageModel | null = null;
|
|
11
|
+
|
|
12
|
+
constructor(config: AgentConfig = {}) {
|
|
13
|
+
super('codex', config);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get or create the language model instance
|
|
18
|
+
*
|
|
19
|
+
* Supports Codex CLI provider options:
|
|
20
|
+
* - reasoningEffort, approvalMode, sandboxMode, mcpServers, verbose, logger
|
|
21
|
+
* - Can use OPENAI_API_KEY environment variable for authentication
|
|
22
|
+
* See: https://ai-sdk.dev/providers/community-providers/codex-cli
|
|
23
|
+
*/
|
|
24
|
+
async getModel(): Promise<LanguageModel> {
|
|
25
|
+
if (!this.modelInstance) {
|
|
26
|
+
// Dynamic import to handle optional peer dependency
|
|
27
|
+
const { codexCli } = await import('ai-sdk-provider-codex-cli');
|
|
28
|
+
|
|
29
|
+
// Codex CLI provider takes model ID as string parameter
|
|
30
|
+
// Uses CLI authentication or OPENAI_API_KEY env var
|
|
31
|
+
// Current models: 'gpt-5.2-codex', 'gpt-5.2', 'gpt-5.1-codex-max', 'gpt-5.1-codex-mini'
|
|
32
|
+
const modelId = this.config.model || 'gpt-5.2-codex';
|
|
33
|
+
|
|
34
|
+
// Check if per-model settings are provided
|
|
35
|
+
const hasModelSettings =
|
|
36
|
+
this.config.reasoningEffort !== undefined ||
|
|
37
|
+
this.config.approvalMode !== undefined ||
|
|
38
|
+
this.config.sandboxMode !== undefined ||
|
|
39
|
+
this.config.mcpServers !== undefined ||
|
|
40
|
+
this.config.verbose !== undefined ||
|
|
41
|
+
this.config.logger !== undefined;
|
|
42
|
+
|
|
43
|
+
if (hasModelSettings) {
|
|
44
|
+
// Pass settings as second parameter
|
|
45
|
+
// Using type assertion for flexibility with provider-specific types
|
|
46
|
+
this.modelInstance = codexCli(modelId, {
|
|
47
|
+
reasoningEffort: this.config.reasoningEffort as 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | undefined,
|
|
48
|
+
approvalMode: this.config.approvalMode as 'untrusted' | 'on-failure' | 'on-request' | 'never' | undefined,
|
|
49
|
+
sandboxMode: this.config.sandboxMode as 'read-only' | 'workspace-write' | 'danger-full-access' | undefined,
|
|
50
|
+
mcpServers: this.config.mcpServers as any,
|
|
51
|
+
verbose: this.config.verbose as boolean | undefined,
|
|
52
|
+
logger: this.config.logger as any,
|
|
53
|
+
} as any);
|
|
54
|
+
} else {
|
|
55
|
+
// Create model instance without additional settings
|
|
56
|
+
this.modelInstance = codexCli(modelId);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.modelInstance;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Override configure to reset model instance when config changes
|
|
65
|
+
*/
|
|
66
|
+
configure(config: AgentConfig): void {
|
|
67
|
+
super.configure(config);
|
|
68
|
+
// Reset model instance so it's recreated with new config
|
|
69
|
+
this.modelInstance = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
|
+
import type { LanguageModel } from 'ai';
|
|
3
|
+
import { BaseAgent } from './base-agent.js';
|
|
4
|
+
import type { AgentConfig } from '../types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Intella Lite Agent
|
|
8
|
+
* Lightweight default agent using OpenAI-compatible interface
|
|
9
|
+
* This is a separate implementation from Mielto
|
|
10
|
+
*/
|
|
11
|
+
export class IntellaLiteAgent extends BaseAgent {
|
|
12
|
+
private modelInstance: LanguageModel | null = null;
|
|
13
|
+
|
|
14
|
+
constructor(config: AgentConfig = {}) {
|
|
15
|
+
super('intella-lite', config);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get or create the language model instance
|
|
20
|
+
*/
|
|
21
|
+
getModel(): LanguageModel {
|
|
22
|
+
if (!this.modelInstance) {
|
|
23
|
+
// Use OpenAI provider as base for Intella Lite
|
|
24
|
+
// Default to a lightweight model if not specified
|
|
25
|
+
const modelId = this.config.model || 'gpt-4o-mini';
|
|
26
|
+
|
|
27
|
+
const apiKey = this.config.apiKey || process.env.OPENAI_API_KEY;
|
|
28
|
+
if (!apiKey) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
'OpenAI API key is required for Intella Lite agent. Set OPENAI_API_KEY environment variable or provide apiKey in config.'
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const provider = createOpenAI({
|
|
35
|
+
apiKey,
|
|
36
|
+
baseURL: this.config.baseURL || process.env.OPENAI_BASE_URL,
|
|
37
|
+
headers: this.config.headers,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.modelInstance = provider.chat(modelId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.modelInstance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Override configure to reset model instance when config changes
|
|
48
|
+
*/
|
|
49
|
+
configure(config: AgentConfig): void {
|
|
50
|
+
super.configure(config);
|
|
51
|
+
// Reset model instance so it's recreated with new config
|
|
52
|
+
this.modelInstance = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
|
+
import type { AgentConfig } from '../types.js';
|
|
3
|
+
import type { LanguageModel } from 'ai';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OpenCode Agent
|
|
7
|
+
* Powered by OpenCode SDK provider
|
|
8
|
+
*/
|
|
9
|
+
export class OpenCodeAgent extends BaseAgent {
|
|
10
|
+
private modelInstance: LanguageModel | null = null;
|
|
11
|
+
|
|
12
|
+
constructor(config: AgentConfig = {}) {
|
|
13
|
+
super('opencode', config);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get or create the language model instance
|
|
18
|
+
*/
|
|
19
|
+
async getModel(): Promise<LanguageModel> {
|
|
20
|
+
if (!this.modelInstance) {
|
|
21
|
+
// Dynamic import to handle optional peer dependency
|
|
22
|
+
const { opencode } = await import('ai-sdk-provider-opencode-sdk');
|
|
23
|
+
|
|
24
|
+
// OpenCode provider takes model ID as string parameter
|
|
25
|
+
// Uses CLI authentication (opencode login) - API key not needed in code
|
|
26
|
+
// Model format: 'provider/model-id' (e.g., 'anthropic/claude-sonnet-4-5-20250929')
|
|
27
|
+
const modelId = this.config.model || 'anthropic/claude-sonnet-4-5-20250929';
|
|
28
|
+
|
|
29
|
+
// Create model instance directly
|
|
30
|
+
this.modelInstance = opencode(modelId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return this.modelInstance;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Override configure to reset model instance when config changes
|
|
38
|
+
*/
|
|
39
|
+
configure(config: AgentConfig): void {
|
|
40
|
+
super.configure(config);
|
|
41
|
+
// Reset model instance so it's recreated with new config
|
|
42
|
+
this.modelInstance = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|