@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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced Claude Code Agent Configuration
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates advanced configuration options for the Claude Code agent,
|
|
5
|
+
* including tool permissions, MCP servers, and custom settings.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* 1. Install dependencies: npm install @intella/sdk ai ai-sdk-provider-claude-code
|
|
9
|
+
* 2. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
|
|
10
|
+
* 3. Authenticate: claude login
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IntellaSDK } from '../../src/index';
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const sdk = new IntellaSDK();
|
|
17
|
+
|
|
18
|
+
// Select and configure Claude agent with advanced options
|
|
19
|
+
sdk.selectAgent('claude', {
|
|
20
|
+
model: 'opus', // Most capable model
|
|
21
|
+
|
|
22
|
+
// Tool permissions
|
|
23
|
+
allowedTools: ['Read', 'Write', 'Edit'], // Only allow these tools
|
|
24
|
+
disallowedTools: ['Bash'], // Explicitly disallow Bash
|
|
25
|
+
|
|
26
|
+
// Permission mode
|
|
27
|
+
permissionMode: 'default', // Options: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan'
|
|
28
|
+
|
|
29
|
+
// MCP server configuration (optional)
|
|
30
|
+
// mcpServers: {
|
|
31
|
+
// 'my-server': {
|
|
32
|
+
// command: 'node',
|
|
33
|
+
// args: ['server.js'],
|
|
34
|
+
// },
|
|
35
|
+
// },
|
|
36
|
+
|
|
37
|
+
// Other options
|
|
38
|
+
maxTurns: 10, // Maximum conversation turns
|
|
39
|
+
cwd: process.cwd(), // Working directory
|
|
40
|
+
verbose: true, // Enable debug logging
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
console.log('Claude agent configured with advanced settings\n');
|
|
44
|
+
|
|
45
|
+
// Execute a task that might use tools
|
|
46
|
+
const response = await sdk.executeTask({
|
|
47
|
+
prompt: 'Read the package.json file and summarize the dependencies.',
|
|
48
|
+
systemPrompt: 'You are a helpful coding assistant.',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log('Response:', response.text);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main().catch(console.error);
|
|
55
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Claude Code Agent Usage
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates basic usage of the Claude Code agent
|
|
5
|
+
* through the Intella SDK.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* 1. Install dependencies: npm install @intella/sdk ai ai-sdk-provider-claude-code
|
|
9
|
+
* 2. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
|
|
10
|
+
* 3. Authenticate: claude login
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IntellaSDK } from '../../src/index';
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const sdk = new IntellaSDK();
|
|
17
|
+
|
|
18
|
+
// Verify default agent before selection
|
|
19
|
+
console.log('Default agent before selection:', sdk.getDefaultAgentType());
|
|
20
|
+
console.log('Available agents:', sdk.listAgents());
|
|
21
|
+
console.log('');
|
|
22
|
+
|
|
23
|
+
// Select and configure Claude agent as default
|
|
24
|
+
// Claude Code uses CLI authentication (claude login)
|
|
25
|
+
sdk.selectAgent('claude', {
|
|
26
|
+
model: 'sonnet', // Options: 'opus', 'sonnet', 'haiku'
|
|
27
|
+
verbose: true, // Enable verbose logging to see Claude Code in action
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Verify agent selection
|
|
31
|
+
console.log('Default agent after selection:', sdk.getDefaultAgentType());
|
|
32
|
+
console.log('Claude agent config:', sdk.getAgentConfig('claude'));
|
|
33
|
+
console.log('');
|
|
34
|
+
|
|
35
|
+
// Execute a simple task (will use Claude as it's now the default)
|
|
36
|
+
console.log('Executing task with Claude Code agent...\n');
|
|
37
|
+
const response = await sdk.executeTask(
|
|
38
|
+
'Write a brief explanation of quantum computing in 2-3 sentences.'
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
console.log('\n=== Response ===');
|
|
42
|
+
console.log('Agent Type:', response.agentType);
|
|
43
|
+
console.log('Response:', response.text);
|
|
44
|
+
console.log('\n=== Metadata ===');
|
|
45
|
+
console.log(JSON.stringify(response.metadata, null, 2));
|
|
46
|
+
|
|
47
|
+
// Final verification
|
|
48
|
+
if (response.agentType === 'claude') {
|
|
49
|
+
console.log('\n✅ SUCCESS: Claude Code agent was used!');
|
|
50
|
+
} else {
|
|
51
|
+
console.log(`\n❌ WARNING: Expected 'claude' but got '${response.agentType}'`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main().catch(console.error);
|
|
56
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Model Comparison
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates using different Claude models (Opus, Sonnet, Haiku)
|
|
5
|
+
* to compare their responses to the same prompt.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* 1. Install dependencies: npm install @intella/sdk ai ai-sdk-provider-claude-code
|
|
9
|
+
* 2. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
|
|
10
|
+
* 3. Authenticate: claude login
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IntellaSDK } from '../../src/index';
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const sdk = new IntellaSDK();
|
|
17
|
+
|
|
18
|
+
const prompt = 'Explain the concept of recursion in programming with a simple example.';
|
|
19
|
+
const models = ['haiku', 'sonnet', 'opus'] as const;
|
|
20
|
+
|
|
21
|
+
console.log('Comparing Claude models on the same prompt...\n');
|
|
22
|
+
console.log('Prompt:', prompt);
|
|
23
|
+
console.log('='.repeat(80) + '\n');
|
|
24
|
+
|
|
25
|
+
for (const model of models) {
|
|
26
|
+
console.log(`\n${model.toUpperCase()} Model:`);
|
|
27
|
+
console.log('-'.repeat(80));
|
|
28
|
+
|
|
29
|
+
// Select agent with specific model
|
|
30
|
+
sdk.selectAgent('claude', { model });
|
|
31
|
+
|
|
32
|
+
const startTime = Date.now();
|
|
33
|
+
const response = await sdk.executeTask(prompt);
|
|
34
|
+
const duration = Date.now() - startTime;
|
|
35
|
+
|
|
36
|
+
console.log(response.text);
|
|
37
|
+
console.log(`\nResponse time: ${duration}ms`);
|
|
38
|
+
console.log(`Tokens: ${response.metadata?.usage?.totalTokens || 'N/A'}`);
|
|
39
|
+
console.log('='.repeat(80));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('\nComparison complete!');
|
|
43
|
+
console.log('\nModel characteristics:');
|
|
44
|
+
console.log('- Haiku: Fastest, good for simple tasks');
|
|
45
|
+
console.log('- Sonnet: Balanced performance and capability');
|
|
46
|
+
console.log('- Opus: Most capable, best for complex reasoning');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
main().catch(console.error);
|
|
50
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Agent Orchestration with Claude Code
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates orchestrating multiple agents including Claude Code
|
|
5
|
+
* for complex tasks that benefit from multiple AI perspectives.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* 1. Install dependencies: npm install @intella/sdk ai ai-sdk-provider-claude-code
|
|
9
|
+
* 2. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
|
|
10
|
+
* 3. Authenticate: claude login
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IntellaSDK } from '../../src/index';
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const sdk = new IntellaSDK();
|
|
17
|
+
|
|
18
|
+
// Configure multiple agents
|
|
19
|
+
sdk.configureAgent('claude', {
|
|
20
|
+
model: 'sonnet',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
sdk.configureAgent('intella-lite', {
|
|
24
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
25
|
+
model: 'gpt-4o-mini',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log('Orchestrating task across multiple agents...\n');
|
|
29
|
+
|
|
30
|
+
// Sequential orchestration: Claude analyzes, then Intella Lite refines
|
|
31
|
+
const sequentialResult = await sdk.orchestrateTask(
|
|
32
|
+
{
|
|
33
|
+
prompt: 'Analyze the pros and cons of microservices architecture, then create a summary.',
|
|
34
|
+
systemPrompt: 'You are a software architecture expert.',
|
|
35
|
+
},
|
|
36
|
+
['claude', 'intella-lite'],
|
|
37
|
+
'sequential',
|
|
38
|
+
{
|
|
39
|
+
passResults: true, // Pass Claude's analysis to Intella Lite for summarization
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
console.log('Sequential Orchestration Result:');
|
|
44
|
+
console.log('='.repeat(50));
|
|
45
|
+
console.log(sequentialResult.result);
|
|
46
|
+
console.log('\nAgent Responses:');
|
|
47
|
+
sequentialResult.agentResponses.forEach((agentResponse, index) => {
|
|
48
|
+
console.log(`\n${index + 1}. ${agentResponse.agentType}:`);
|
|
49
|
+
console.log(agentResponse.response.substring(0, 200) + '...');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
console.log('\n\n' + '='.repeat(50) + '\n');
|
|
53
|
+
|
|
54
|
+
// Parallel orchestration: Get multiple perspectives simultaneously
|
|
55
|
+
const parallelResult = await sdk.orchestrateTask(
|
|
56
|
+
'What are the key considerations when choosing a database for a new project?',
|
|
57
|
+
['claude', 'intella-lite'],
|
|
58
|
+
'parallel',
|
|
59
|
+
{
|
|
60
|
+
combineStrategy: 'merge', // Combine all responses
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
console.log('Parallel Orchestration Result:');
|
|
65
|
+
console.log('='.repeat(50));
|
|
66
|
+
console.log(parallelResult.result);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
main().catch(console.error);
|
|
70
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming with Claude Code Agent
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to stream responses from the Claude Code agent.
|
|
5
|
+
*
|
|
6
|
+
* Prerequisites:
|
|
7
|
+
* 1. Install dependencies: npm install @intella/sdk ai ai-sdk-provider-claude-code
|
|
8
|
+
* 2. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
|
|
9
|
+
* 3. Authenticate: claude login
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { IntellaSDK, extractCodeBlock } from '../../src/index';
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
const sdk = new IntellaSDK();
|
|
16
|
+
|
|
17
|
+
// Select and configure Claude agent
|
|
18
|
+
sdk.selectAgent('intella-lite', {
|
|
19
|
+
model: 'gpt-4o-mini',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log('Streaming response from Claude Code agent...\n');
|
|
23
|
+
|
|
24
|
+
let code = ''
|
|
25
|
+
|
|
26
|
+
let chunks = []
|
|
27
|
+
|
|
28
|
+
// Stream the response
|
|
29
|
+
for await (const chunk of sdk.streamTask(
|
|
30
|
+
'Write a python script to generate ascii art of a cat'
|
|
31
|
+
)) {
|
|
32
|
+
// Write each chunk as it arrives
|
|
33
|
+
process.stdout.write(chunk.text);
|
|
34
|
+
chunks.push(chunk.text);
|
|
35
|
+
|
|
36
|
+
if (chunk.isDone) {
|
|
37
|
+
console.log('\n\nStreaming complete!');
|
|
38
|
+
console.log('Agent Type:', chunk.agentType);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let response = chunks.join('');
|
|
43
|
+
|
|
44
|
+
console.log('Response:', response);
|
|
45
|
+
|
|
46
|
+
// Extract the code from the response
|
|
47
|
+
|
|
48
|
+
const codeBlock = extractCodeBlock(response, 'python');
|
|
49
|
+
if (!codeBlock) {
|
|
50
|
+
throw new Error('No python code block found');
|
|
51
|
+
}
|
|
52
|
+
code = codeBlock.code;
|
|
53
|
+
|
|
54
|
+
// Execute the code
|
|
55
|
+
|
|
56
|
+
console.log('Code:', code);
|
|
57
|
+
|
|
58
|
+
const sandbox = await sdk.initializeSandbox('e2b', {
|
|
59
|
+
templateId: 'base',
|
|
60
|
+
});
|
|
61
|
+
const result = await sandbox.runCode(code, {
|
|
62
|
+
language: 'python',
|
|
63
|
+
});
|
|
64
|
+
console.log('Result:', result);
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main().catch(console.error);
|
|
69
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "../..",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"types": ["node"],
|
|
10
|
+
"lib": ["ES2020"],
|
|
11
|
+
"baseUrl": "../..",
|
|
12
|
+
"paths": {
|
|
13
|
+
"@intella/sdk": ["./src/index.ts"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": ["*.ts", "../../src/**/*.ts"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Code Extractor Utility Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to use the code extractor utility functions to extract code blocks from LLM responses in markdown format.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
### `extractCodeBlocks(text, options?)`
|
|
8
|
+
|
|
9
|
+
Extracts all code blocks from markdown text. Returns an array of `CodeBlock` objects or code strings.
|
|
10
|
+
|
|
11
|
+
**Options:**
|
|
12
|
+
- `languages?: string[]` - Filter by specific language(s) (case-insensitive)
|
|
13
|
+
- `codeOnly?: boolean` - Return only code strings instead of full objects
|
|
14
|
+
- `includeFullMatch?: boolean` - Include the full match including fences
|
|
15
|
+
- `customWrapper?: { start: string; end: string }` - Use custom wrapper strings instead of default ``` markers
|
|
16
|
+
|
|
17
|
+
### `extractCodeBlock(text, language?)`
|
|
18
|
+
|
|
19
|
+
Extracts the first code block from markdown text. Optionally filter by language.
|
|
20
|
+
|
|
21
|
+
### `extractCode(text, language?)`
|
|
22
|
+
|
|
23
|
+
Extracts the code content from the first code block as a string. Optionally filter by language.
|
|
24
|
+
|
|
25
|
+
## Usage Examples
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { extractCodeBlocks, extractCodeBlock, extractCode } from '@intella/sdk';
|
|
29
|
+
|
|
30
|
+
const markdown = `
|
|
31
|
+
Here's some code:
|
|
32
|
+
\`\`\`typescript
|
|
33
|
+
const x = 1;
|
|
34
|
+
\`\`\`
|
|
35
|
+
|
|
36
|
+
And a command:
|
|
37
|
+
\`\`\`bash
|
|
38
|
+
npm install
|
|
39
|
+
\`\`\`
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
// Extract all code blocks
|
|
43
|
+
const blocks = extractCodeBlocks(markdown);
|
|
44
|
+
// Returns: [
|
|
45
|
+
// { language: 'typescript', code: 'const x = 1;' },
|
|
46
|
+
// { language: 'bash', code: 'npm install' }
|
|
47
|
+
// ]
|
|
48
|
+
|
|
49
|
+
// Extract only TypeScript blocks
|
|
50
|
+
const tsBlocks = extractCodeBlocks(markdown, { languages: ['typescript'] });
|
|
51
|
+
|
|
52
|
+
// Extract only code strings
|
|
53
|
+
const codeStrings = extractCodeBlocks(markdown, { codeOnly: true });
|
|
54
|
+
// Returns: ['const x = 1;', 'npm install']
|
|
55
|
+
|
|
56
|
+
// Extract first block
|
|
57
|
+
const firstBlock = extractCodeBlock(markdown);
|
|
58
|
+
// Returns: { language: 'typescript', code: 'const x = 1;' }
|
|
59
|
+
|
|
60
|
+
// Extract code string only
|
|
61
|
+
const code = extractCode(markdown, 'bash');
|
|
62
|
+
// Returns: 'npm install'
|
|
63
|
+
|
|
64
|
+
// Using custom wrapper
|
|
65
|
+
const customMarkdown = '<code>typescript\nconst x = 1;\n</code>';
|
|
66
|
+
const customBlocks = extractCodeBlocks(customMarkdown, {
|
|
67
|
+
customWrapper: { start: '<code>', end: '</code>' }
|
|
68
|
+
});
|
|
69
|
+
// Returns: [{ language: 'typescript', code: 'const x = 1;' }]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Running the Example
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# From the SDK root directory
|
|
76
|
+
npx tsx examples/code-extractor/example.ts
|
|
77
|
+
```
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Extractor Utility Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the code extractor utility
|
|
5
|
+
* to extract code blocks from LLM responses in markdown format.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
extractCodeBlocks,
|
|
10
|
+
extractCodeBlock,
|
|
11
|
+
extractCode,
|
|
12
|
+
type CodeBlock,
|
|
13
|
+
} from '../../src/index';
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
// Example markdown text with multiple code blocks
|
|
17
|
+
const markdownText = `
|
|
18
|
+
Here's a TypeScript example:
|
|
19
|
+
|
|
20
|
+
\`\`\`typescript
|
|
21
|
+
function greet(name: string): string {
|
|
22
|
+
return \`Hello, \${name}!\`;
|
|
23
|
+
}
|
|
24
|
+
\`\`\`
|
|
25
|
+
|
|
26
|
+
And here's a bash command:
|
|
27
|
+
|
|
28
|
+
\`\`\`bash
|
|
29
|
+
npm install @intella/sdk
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
Finally, some Python code:
|
|
33
|
+
|
|
34
|
+
\`\`\`python
|
|
35
|
+
def calculate_sum(a, b):
|
|
36
|
+
return a + b
|
|
37
|
+
\`\`\`
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
console.log('=== Example 1: Extract All Code Blocks ===\n');
|
|
41
|
+
const allBlocks = extractCodeBlocks(markdownText) as CodeBlock[];
|
|
42
|
+
console.log(`Found ${allBlocks.length} code blocks:\n`);
|
|
43
|
+
allBlocks.forEach((block, index) => {
|
|
44
|
+
console.log(`Block ${index + 1}:`);
|
|
45
|
+
console.log(` Language: ${block.language || '(none)'}`);
|
|
46
|
+
console.log(` Code:\n${block.code}\n`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log('\n=== Example 2: Extract Only TypeScript Blocks ===\n');
|
|
50
|
+
const tsBlocks = extractCodeBlocks(markdownText, {
|
|
51
|
+
languages: ['typescript'],
|
|
52
|
+
}) as CodeBlock[];
|
|
53
|
+
console.log(`Found ${tsBlocks.length} TypeScript block(s):\n`);
|
|
54
|
+
tsBlocks.forEach((block) => {
|
|
55
|
+
console.log(`Language: ${block.language}`);
|
|
56
|
+
console.log(`Code:\n${block.code}\n`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('\n=== Example 3: Extract Code Strings Only ===\n');
|
|
60
|
+
const codeStrings = extractCodeBlocks(markdownText, {
|
|
61
|
+
codeOnly: true,
|
|
62
|
+
}) as string[];
|
|
63
|
+
console.log(`Extracted ${codeStrings.length} code strings:\n`);
|
|
64
|
+
codeStrings.forEach((code, index) => {
|
|
65
|
+
console.log(`Code ${index + 1}:\n${code}\n`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log('\n=== Example 4: Extract Single Code Block ===\n');
|
|
69
|
+
const bashBlock = extractCodeBlock(markdownText, 'bash');
|
|
70
|
+
if (bashBlock) {
|
|
71
|
+
console.log('Found bash block:');
|
|
72
|
+
console.log(`Language: ${bashBlock.language}`);
|
|
73
|
+
console.log(`Code: ${bashBlock.code}\n`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log('\n=== Example 5: Extract Code String Only ===\n');
|
|
77
|
+
const pythonCode = extractCode(markdownText, 'python');
|
|
78
|
+
if (pythonCode) {
|
|
79
|
+
console.log('Python code:');
|
|
80
|
+
console.log(pythonCode);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log('\n=== Example 6: Extract with Full Match ===\n');
|
|
84
|
+
const blocksWithMatch = extractCodeBlocks(markdownText, {
|
|
85
|
+
includeFullMatch: true,
|
|
86
|
+
}) as CodeBlock[];
|
|
87
|
+
console.log('First block with full match:');
|
|
88
|
+
if (blocksWithMatch[0]?.fullMatch) {
|
|
89
|
+
console.log(blocksWithMatch[0].fullMatch);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Example: Using with LLM response
|
|
93
|
+
console.log('\n=== Example 7: Real-world Usage with LLM Response ===\n');
|
|
94
|
+
const llmResponse = `
|
|
95
|
+
I'll help you create a function. Here's the code:
|
|
96
|
+
|
|
97
|
+
\`\`\`typescript
|
|
98
|
+
export function add(a: number, b: number): number {
|
|
99
|
+
return a + b;
|
|
100
|
+
}
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
You can test it with:
|
|
104
|
+
|
|
105
|
+
\`\`\`bash
|
|
106
|
+
npm test
|
|
107
|
+
\`\`\`
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const extractedCode = extractCode(llmResponse, 'typescript');
|
|
111
|
+
if (extractedCode) {
|
|
112
|
+
console.log('Extracted TypeScript code from LLM response:');
|
|
113
|
+
console.log(extractedCode);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Example: Using custom wrapper
|
|
117
|
+
console.log('\n=== Example 8: Using Custom Wrapper ===\n');
|
|
118
|
+
const customMarkdown = `
|
|
119
|
+
Here's some code with custom tags:
|
|
120
|
+
|
|
121
|
+
<code>typescript
|
|
122
|
+
function hello() {
|
|
123
|
+
console.log('Hello!');
|
|
124
|
+
}
|
|
125
|
+
</code>
|
|
126
|
+
|
|
127
|
+
And another one:
|
|
128
|
+
|
|
129
|
+
<code>bash
|
|
130
|
+
echo "Hello World"
|
|
131
|
+
</code>
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
const customBlocks = extractCodeBlocks(customMarkdown, {
|
|
135
|
+
customWrapper: { start: '<code>', end: '</code>' },
|
|
136
|
+
}) as CodeBlock[];
|
|
137
|
+
console.log(`Found ${customBlocks.length} code blocks with custom wrapper:\n`);
|
|
138
|
+
customBlocks.forEach((block, index) => {
|
|
139
|
+
console.log(`Block ${index + 1}:`);
|
|
140
|
+
console.log(` Language: ${block.language || '(none)'}`);
|
|
141
|
+
console.log(` Code:\n${block.code}\n`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { IntellaSDK } from '../../src/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Basic example demonstrating filesystem usage with Intella SDK
|
|
5
|
+
*/
|
|
6
|
+
async function main() {
|
|
7
|
+
const sdk = new IntellaSDK();
|
|
8
|
+
|
|
9
|
+
// Initialize filesystem with AgentFS provider
|
|
10
|
+
console.log('Initializing AgentFS filesystem...');
|
|
11
|
+
await sdk.initializeFilesystem('agentfs', {
|
|
12
|
+
agentId: 'example-agent',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Filesystem operations
|
|
16
|
+
console.log('\n=== Filesystem Operations ===');
|
|
17
|
+
|
|
18
|
+
// Write a file
|
|
19
|
+
await sdk.writeFile('/hello.txt', 'Hello from Intella SDK!');
|
|
20
|
+
console.log('✓ Wrote /hello.txt');
|
|
21
|
+
|
|
22
|
+
// Read the file
|
|
23
|
+
const content = await sdk.readFile('/hello.txt');
|
|
24
|
+
console.log(`✓ Read /hello.txt: ${content}`);
|
|
25
|
+
|
|
26
|
+
// Create a directory
|
|
27
|
+
await sdk.createDirectory('/output', true);
|
|
28
|
+
console.log('✓ Created /output directory');
|
|
29
|
+
|
|
30
|
+
// Write a file in the directory
|
|
31
|
+
await sdk.writeFile('/output/report.txt', 'This is a report');
|
|
32
|
+
console.log('✓ Wrote /output/report.txt');
|
|
33
|
+
|
|
34
|
+
// List directory contents
|
|
35
|
+
const entries = await sdk.readDirectory('/output');
|
|
36
|
+
console.log(`✓ Directory /output contains ${entries.length} entries:`);
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
console.log(` - ${entry.name} (${entry.stats.isDirectory ? 'dir' : 'file'})`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Key-value operations
|
|
42
|
+
console.log('\n=== Key-Value Operations ===');
|
|
43
|
+
|
|
44
|
+
await sdk.setValue('user:preferences', { theme: 'dark', language: 'en' });
|
|
45
|
+
console.log('✓ Set user preferences');
|
|
46
|
+
|
|
47
|
+
const preferences = await sdk.getValue('user:preferences');
|
|
48
|
+
console.log(`✓ Got user preferences:`, preferences);
|
|
49
|
+
|
|
50
|
+
// Tool call tracking
|
|
51
|
+
console.log('\n=== Tool Call Tracking ===');
|
|
52
|
+
|
|
53
|
+
await sdk.recordToolCall({
|
|
54
|
+
tool: 'web_search',
|
|
55
|
+
startedAt: Date.now() / 1000 - 5,
|
|
56
|
+
endedAt: Date.now() / 1000 - 4,
|
|
57
|
+
input: { query: 'AI agents' },
|
|
58
|
+
output: { results: ['result1', 'result2'] },
|
|
59
|
+
status: 'success',
|
|
60
|
+
});
|
|
61
|
+
console.log('✓ Recorded tool call');
|
|
62
|
+
|
|
63
|
+
const history = await sdk.getToolCallHistory({ limit: 10 });
|
|
64
|
+
console.log(`✓ Retrieved ${history.length} tool calls from history`);
|
|
65
|
+
|
|
66
|
+
// Using memory provider (ephemeral, in-memory)
|
|
67
|
+
console.log('\n=== Memory Provider (Ephemeral) ===');
|
|
68
|
+
|
|
69
|
+
await sdk.closeFilesystem();
|
|
70
|
+
await sdk.initializeFilesystem('memory');
|
|
71
|
+
|
|
72
|
+
await sdk.writeFile('/temp.txt', 'Temporary file');
|
|
73
|
+
console.log('✓ Wrote temporary file to memory filesystem');
|
|
74
|
+
|
|
75
|
+
const tempContent = await sdk.readFile('/temp.txt');
|
|
76
|
+
console.log(`✓ Read temporary file: ${tempContent}`);
|
|
77
|
+
|
|
78
|
+
// Cleanup
|
|
79
|
+
await sdk.closeFilesystem();
|
|
80
|
+
console.log('\n✓ Closed filesystem');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch(console.error);
|
|
84
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Integrated Task Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to use **Agent**, **FileSystem**, and **Sandbox** together to carry out a complete task.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The example shows a complete workflow:
|
|
8
|
+
|
|
9
|
+
1. **Agent** generates Python code to calculate Fibonacci numbers
|
|
10
|
+
2. **FileSystem** stores the generated code and results
|
|
11
|
+
3. **Sandbox** executes the code in an isolated environment
|
|
12
|
+
4. Results are read back and analyzed by the **Agent**
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- Node.js 18+ or Bun
|
|
17
|
+
- Environment variables:
|
|
18
|
+
- `E2B_API_KEY` - For E2B sandbox (or use Daytona)
|
|
19
|
+
- `ANTHROPIC_API_KEY` - For Claude agent (or use another agent)
|
|
20
|
+
|
|
21
|
+
## Running the Example
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Install dependencies (if not already installed)
|
|
25
|
+
cd packages/intella-sdk
|
|
26
|
+
bun install
|
|
27
|
+
|
|
28
|
+
# Run the example
|
|
29
|
+
bun run examples/integrated-task/integrated-usage.ts
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or with Node.js:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx tsx examples/integrated-task/integrated-usage.ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## What It Does
|
|
39
|
+
|
|
40
|
+
1. **Initializes Filesystem** - Sets up a memory-based filesystem for storing code and results
|
|
41
|
+
2. **Initializes Sandbox** - Creates an E2B sandbox environment for code execution
|
|
42
|
+
3. **Configures Agent** - Sets up Claude Sonnet to generate code
|
|
43
|
+
4. **Generates Code** - Agent creates a Python script for Fibonacci calculation
|
|
44
|
+
5. **Saves Code** - Code is stored in the filesystem
|
|
45
|
+
6. **Executes in Sandbox** - The script runs in the isolated sandbox environment
|
|
46
|
+
7. **Reads Results** - Results are retrieved from the sandbox
|
|
47
|
+
8. **Persists Data** - Results are saved back to filesystem
|
|
48
|
+
9. **Analyzes Results** - Agent analyzes the generated Fibonacci sequence
|
|
49
|
+
10. **Tracks Metadata** - Tool calls are recorded for audit/debugging
|
|
50
|
+
|
|
51
|
+
## Customization
|
|
52
|
+
|
|
53
|
+
You can modify this example to:
|
|
54
|
+
|
|
55
|
+
- Use different agents (intella-lite, codex, opencode)
|
|
56
|
+
- Use different sandbox providers (daytona instead of e2b)
|
|
57
|
+
- Use persistent filesystem (agentfs instead of memory)
|
|
58
|
+
- Change the task to generate different types of code
|
|
59
|
+
- Add more complex workflows with multiple agent interactions
|
|
60
|
+
|
|
61
|
+
## Key Concepts
|
|
62
|
+
|
|
63
|
+
- **Agent**: Generates code, analyzes results, provides AI capabilities
|
|
64
|
+
- **FileSystem**: Persistent storage for code, data, and metadata
|
|
65
|
+
- **Sandbox**: Isolated execution environment for running code safely
|
|
66
|
+
|
|
67
|
+
Together, these three components enable powerful AI-driven development workflows.
|
|
68
|
+
|