-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbasic-usage.js
More file actions
108 lines (93 loc) · 3.28 KB
/
Copy pathbasic-usage.js
File metadata and controls
108 lines (93 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Basic Usage Example - JavaScript
*
* This example shows how to use the TealTiger SDK in a simple JavaScript application
*/
const { TealTiger } = require('tealtiger');
async function basicExample() {
console.log('🚀 TealTiger SDK - Basic Usage Example');
console.log('======================================');
// Initialize the SDK
const tealTiger = new TealTiger({
apiKey: 'test-api-key-12345',
ssaUrl: 'http://localhost:3001',
debug: true
});
try {
// Check if the Security Sidecar Agent is healthy
console.log('\n1. Health Check');
const health = await tealTiger.healthCheck();
console.log('✅ SSA Health:', health);
// Example 1: Safe web search (should be allowed)
console.log('\n2. Safe Web Search');
const searchResult = await tealTiger.executeTool(
'web-search',
{ query: 'AI security best practices' },
undefined,
async (toolName, params) => {
// Mock tool execution
console.log(`🔧 Executing ${toolName} with params:`, params);
return {
tool: toolName,
query: params.query,
results: [
{ title: 'AI Security Guide', url: 'https://example.com/guide' },
{ title: 'Best Practices', url: 'https://example.com/practices' }
]
};
}
);
console.log('✅ Search Result:', searchResult);
// Example 2: System command (should be denied)
console.log('\n3. System Command (Should be Denied)');
const systemResult = await tealTiger.executeTool(
'system-command',
{ command: 'ls -la' },
undefined,
async (toolName, params) => {
// This won't be executed due to security denial
console.log(`🔧 Executing ${toolName} with params:`, params);
return { output: 'file1.txt file2.txt' };
}
);
console.log('❌ System Command Result:', systemResult);
// Example 3: File write (should be transformed)
console.log('\n4. File Write (Should be Transformed)');
const writeResult = await tealTiger.executeTool(
'file-write',
{ path: '/tmp/test.txt', content: 'Hello World' },
undefined,
async (toolName, params) => {
console.log(`🔧 Executing ${toolName} with params:`, params);
// The tool name might be transformed to 'file-read'
if (toolName === 'file-read') {
return { content: 'Mock file content', path: params.path };
} else {
return { success: true, path: params.path };
}
}
);
console.log('🔄 Write Result:', writeResult);
// Get SDK statistics
console.log('\n5. SDK Statistics');
const stats = tealTiger.getStatistics();
console.log('📊 Statistics:', stats);
// Get audit trail
console.log('\n6. Audit Trail');
const auditTrail = await tealTiger.getAuditTrail({ limit: 5 });
console.log('📝 Recent Audit Entries:', auditTrail.auditTrail.entries.length);
} catch (error) {
console.error('❌ Error:', error.message);
if (error.code) {
console.error('Error Code:', error.code);
}
if (error.details) {
console.error('Error Details:', error.details);
}
}
}
// Run the example
if (require.main === module) {
basicExample().catch(console.error);
}
module.exports = { basicExample };