connectonion 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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -0
  3. package/dist/connect.d.ts +35 -0
  4. package/dist/connect.d.ts.map +1 -0
  5. package/dist/connect.js +149 -0
  6. package/dist/console.d.ts +30 -0
  7. package/dist/console.d.ts.map +1 -0
  8. package/dist/console.js +124 -0
  9. package/dist/core/agent.d.ts +233 -0
  10. package/dist/core/agent.d.ts.map +1 -0
  11. package/dist/core/agent.js +500 -0
  12. package/dist/examples/comprehensive-test.js +314 -0
  13. package/dist/examples/simple-test.js +80 -0
  14. package/dist/history/index.d.ts +42 -0
  15. package/dist/history/index.d.ts.map +1 -0
  16. package/dist/history/index.js +140 -0
  17. package/dist/index.d.ts +20 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +53 -0
  20. package/dist/llm/anthropic.d.ts +23 -0
  21. package/dist/llm/anthropic.d.ts.map +1 -0
  22. package/dist/llm/anthropic.js +139 -0
  23. package/dist/llm/gemini.d.ts +20 -0
  24. package/dist/llm/gemini.d.ts.map +1 -0
  25. package/dist/llm/gemini.js +136 -0
  26. package/dist/llm/index.d.ts +18 -0
  27. package/dist/llm/index.d.ts.map +1 -0
  28. package/dist/llm/index.js +76 -0
  29. package/dist/llm/llm-do.d.ts +8 -0
  30. package/dist/llm/llm-do.d.ts.map +1 -0
  31. package/dist/llm/llm-do.js +25 -0
  32. package/dist/llm/noop.d.ts +16 -0
  33. package/dist/llm/noop.d.ts.map +1 -0
  34. package/dist/llm/noop.js +23 -0
  35. package/dist/llm/openai.d.ts +21 -0
  36. package/dist/llm/openai.d.ts.map +1 -0
  37. package/dist/llm/openai.js +131 -0
  38. package/dist/src/core/agent.js +368 -0
  39. package/dist/src/history/index.js +140 -0
  40. package/dist/src/index.js +34 -0
  41. package/dist/src/llm/index.js +22 -0
  42. package/dist/src/llm/openai.js +78 -0
  43. package/dist/src/tools/tool-utils.js +348 -0
  44. package/dist/src/types.js +8 -0
  45. package/dist/tools/email.d.ts +13 -0
  46. package/dist/tools/email.d.ts.map +1 -0
  47. package/dist/tools/email.js +98 -0
  48. package/dist/tools/replay.d.ts +19 -0
  49. package/dist/tools/replay.d.ts.map +1 -0
  50. package/dist/tools/replay.js +62 -0
  51. package/dist/tools/tool-executor.d.ts +58 -0
  52. package/dist/tools/tool-executor.d.ts.map +1 -0
  53. package/dist/tools/tool-executor.js +100 -0
  54. package/dist/tools/tool-utils.d.ts +133 -0
  55. package/dist/tools/tool-utils.d.ts.map +1 -0
  56. package/dist/tools/tool-utils.js +380 -0
  57. package/dist/tools/xray.d.ts +58 -0
  58. package/dist/tools/xray.d.ts.map +1 -0
  59. package/dist/tools/xray.js +110 -0
  60. package/dist/trust/index.d.ts +26 -0
  61. package/dist/trust/index.d.ts.map +1 -0
  62. package/dist/trust/index.js +47 -0
  63. package/dist/trust/tools.d.ts +4 -0
  64. package/dist/trust/tools.d.ts.map +1 -0
  65. package/dist/trust/tools.js +71 -0
  66. package/dist/types.d.ts +141 -0
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/types.js +10 -0
  69. package/package.json +63 -0
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+ /**
3
+ * Comprehensive test to verify all ConnectOnion functionality
4
+ * This tests core logic, error handling, and edge cases
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const src_1 = require("../src");
41
+ const dotenv = __importStar(require("dotenv"));
42
+ dotenv.config();
43
+ // Test counters
44
+ let testsPassed = 0;
45
+ let testsFailed = 0;
46
+ function assert(condition, message) {
47
+ if (condition) {
48
+ console.log(`✅ ${message}`);
49
+ testsPassed++;
50
+ }
51
+ else {
52
+ console.error(`❌ ${message}`);
53
+ testsFailed++;
54
+ }
55
+ }
56
+ async function testBasicToolConversion() {
57
+ console.log('\n🧪 Testing Basic Tool Conversion...');
58
+ // Test 1: Simple function conversion
59
+ function add(a, b) {
60
+ return a + b;
61
+ }
62
+ const tool = (0, src_1.createToolFromFunction)(add);
63
+ assert(tool.name === 'add', 'Tool name should be "add"');
64
+ assert(tool.description === 'Execute the add tool.', 'Default description should be set');
65
+ const result = tool.run({ a: 5, b: 3 });
66
+ assert(result === 8, 'Tool should calculate 5 + 3 = 8');
67
+ // Test 2: Function with JSDoc
68
+ function multiply(x, y) {
69
+ /** Multiply two numbers */
70
+ return x * y;
71
+ }
72
+ const tool2 = (0, src_1.createToolFromFunction)(multiply);
73
+ const schema = tool2.toFunctionSchema();
74
+ assert(schema.name === 'multiply', 'Schema name should match function name');
75
+ assert(schema.parameters.properties.hasOwnProperty('x'), 'Should have parameter x');
76
+ assert(schema.parameters.properties.hasOwnProperty('y'), 'Should have parameter y');
77
+ }
78
+ async function testClassTools() {
79
+ console.log('\n🧪 Testing Class-based Tools...');
80
+ class Calculator {
81
+ constructor() {
82
+ this.state = 0;
83
+ }
84
+ add(value) {
85
+ this.state += value;
86
+ return this.state;
87
+ }
88
+ subtract(value) {
89
+ this.state -= value;
90
+ return this.state;
91
+ }
92
+ getState() {
93
+ return this.state;
94
+ }
95
+ _reset() {
96
+ this.state = 0;
97
+ }
98
+ }
99
+ const calc = new Calculator();
100
+ const tools = (0, src_1.extractMethodsFromInstance)(calc);
101
+ assert(tools.length === 3, 'Should extract 3 public methods (not private ones)');
102
+ assert(tools.some(t => t.name === 'add'), 'Should have add method');
103
+ assert(tools.some(t => t.name === 'subtract'), 'Should have subtract method');
104
+ assert(!tools.some(t => t.name === '_reset'), 'Should not extract private methods');
105
+ // Test that methods maintain context
106
+ const addTool = tools.find(t => t.name === 'add');
107
+ const stateTool = tools.find(t => t.name === 'getState');
108
+ if (addTool && stateTool) {
109
+ addTool.run({ value: 10 });
110
+ const state = stateTool.run({});
111
+ assert(state === 10, 'Methods should maintain class instance context');
112
+ }
113
+ }
114
+ async function testAgentCreation() {
115
+ console.log('\n🧪 Testing Agent Creation...');
116
+ try {
117
+ // Test without API key should throw
118
+ const originalKey = process.env.OPENAI_API_KEY;
119
+ delete process.env.OPENAI_API_KEY;
120
+ let errorThrown = false;
121
+ try {
122
+ new src_1.Agent({ name: 'test' });
123
+ }
124
+ catch (e) {
125
+ errorThrown = true;
126
+ }
127
+ assert(errorThrown, 'Should throw error when no API key is provided');
128
+ // Restore key
129
+ process.env.OPENAI_API_KEY = originalKey;
130
+ // Test with API key
131
+ const agent = new src_1.Agent({
132
+ name: 'test-agent',
133
+ systemPrompt: 'Test prompt',
134
+ maxIterations: 5
135
+ });
136
+ assert(agent.getTools().length === 0, 'Agent should start with no tools');
137
+ // Test adding tools
138
+ function testTool() {
139
+ return 'test';
140
+ }
141
+ agent.addTool(testTool);
142
+ assert(agent.getTools().length === 1, 'Should have 1 tool after adding');
143
+ // Test removing tools
144
+ agent.removeTool('testTool');
145
+ assert(agent.getTools().length === 0, 'Should have 0 tools after removing');
146
+ }
147
+ catch (error) {
148
+ console.error('Agent creation test error:', error);
149
+ }
150
+ }
151
+ async function testErrorHandling() {
152
+ console.log('\n🧪 Testing Error Handling...');
153
+ // Test tool that throws error
154
+ function errorTool() {
155
+ throw new Error('Tool error!');
156
+ }
157
+ const agent = new src_1.Agent({
158
+ name: 'error-test',
159
+ tools: [errorTool]
160
+ });
161
+ // Test that agent handles tool errors gracefully
162
+ try {
163
+ // We can't test actual LLM calls without mocking, but we can test tool execution
164
+ const tool = agent.getTools()[0];
165
+ let errorCaught = false;
166
+ try {
167
+ tool.run({});
168
+ }
169
+ catch (e) {
170
+ errorCaught = true;
171
+ }
172
+ assert(errorCaught, 'Tool.run should throw errors for the agent to handle');
173
+ }
174
+ catch (error) {
175
+ console.error('Error handling test failed:', error);
176
+ }
177
+ }
178
+ async function testProcessTools() {
179
+ console.log('\n🧪 Testing processTools Utility...');
180
+ function func1() { return 'func1'; }
181
+ function func2() { return 'func2'; }
182
+ class TestClass {
183
+ method1() { return 'method1'; }
184
+ method2() { return 'method2'; }
185
+ }
186
+ // Test single function
187
+ let tools = (0, src_1.processTools)(func1);
188
+ assert(tools.length === 1, 'Single function should produce 1 tool');
189
+ // Test array of functions
190
+ tools = (0, src_1.processTools)([func1, func2]);
191
+ assert(tools.length === 2, 'Array of 2 functions should produce 2 tools');
192
+ // Test class instance
193
+ tools = (0, src_1.processTools)(new TestClass());
194
+ assert(tools.length === 2, 'Class with 2 methods should produce 2 tools');
195
+ // Test mixed array
196
+ tools = (0, src_1.processTools)([func1, new TestClass(), func2]);
197
+ assert(tools.length === 4, 'Mixed array should produce correct number of tools');
198
+ // Test empty input
199
+ tools = (0, src_1.processTools)(null);
200
+ assert(tools.length === 0, 'Null input should produce empty array');
201
+ tools = (0, src_1.processTools)(undefined);
202
+ assert(tools.length === 0, 'Undefined input should produce empty array');
203
+ }
204
+ async function testHistoryTracking() {
205
+ console.log('\n🧪 Testing History Tracking...');
206
+ const agent = new src_1.Agent({
207
+ name: 'history-test-' + Date.now() // Unique name to avoid conflicts
208
+ });
209
+ // Initially should be empty
210
+ let history = agent.getHistory();
211
+ assert(history.length === 0, 'History should start empty');
212
+ // Clear history
213
+ agent.clearHistory();
214
+ history = agent.getHistory();
215
+ assert(history.length === 0, 'History should be empty after clear');
216
+ }
217
+ async function testToolWithOptionalParams() {
218
+ console.log('\n🧪 Testing Tools with Optional Parameters...');
219
+ function greet(name, title) {
220
+ return title ? `Hello, ${title} ${name}` : `Hello, ${name}`;
221
+ }
222
+ const tool = (0, src_1.createToolFromFunction)(greet);
223
+ const schema = tool.toFunctionSchema();
224
+ assert(schema.parameters.required?.includes('name'), 'name should be required');
225
+ assert(!schema.parameters.required?.includes('title'), 'title should not be required');
226
+ // Test execution with and without optional param
227
+ const result1 = tool.run({ name: 'Alice' });
228
+ assert(result1 === 'Hello, Alice', 'Should work without optional param');
229
+ const result2 = tool.run({ name: 'Alice', title: 'Dr.' });
230
+ assert(result2 === 'Hello, Dr. Alice', 'Should work with optional param');
231
+ }
232
+ async function testAsyncTools() {
233
+ console.log('\n🧪 Testing Async Tools...');
234
+ async function asyncTool(delay) {
235
+ await new Promise(resolve => setTimeout(resolve, delay));
236
+ return `Waited ${delay}ms`;
237
+ }
238
+ const tool = (0, src_1.createToolFromFunction)(asyncTool);
239
+ const result = await tool.run({ delay: 10 });
240
+ assert(result === 'Waited 10ms', 'Async tool should work correctly');
241
+ }
242
+ async function testToolNaming() {
243
+ console.log('\n🧪 Testing Tool Naming...');
244
+ // Test regular function
245
+ function myFunction() { }
246
+ let tool = (0, src_1.createToolFromFunction)(myFunction);
247
+ assert(tool.name === 'myFunction', 'Regular function name should be preserved');
248
+ // Test arrow function with name
249
+ const namedArrow = function arrowFunc() { };
250
+ tool = (0, src_1.createToolFromFunction)(namedArrow);
251
+ assert(tool.name === 'arrowFunc', 'Named arrow function should preserve name');
252
+ // Test anonymous function
253
+ tool = (0, src_1.createToolFromFunction)(function () { });
254
+ assert(tool.name === 'anonymous', 'Anonymous function should be named "anonymous"');
255
+ }
256
+ async function testEdgeCases() {
257
+ console.log('\n🧪 Testing Edge Cases...');
258
+ // Test function with no parameters
259
+ function noParams() {
260
+ return 'no params';
261
+ }
262
+ const tool1 = (0, src_1.createToolFromFunction)(noParams);
263
+ const result1 = tool1.run({});
264
+ assert(result1 === 'no params', 'Function with no params should work');
265
+ // Test function returning different types
266
+ function returnObject() {
267
+ return { key: 'value' };
268
+ }
269
+ const tool2 = (0, src_1.createToolFromFunction)(returnObject);
270
+ const result2 = tool2.run({});
271
+ assert(typeof result2 === 'object' && result2.key === 'value', 'Should handle object return');
272
+ // Test function returning null
273
+ function returnNull() {
274
+ return null;
275
+ }
276
+ const tool3 = (0, src_1.createToolFromFunction)(returnNull);
277
+ const result3 = tool3.run({});
278
+ assert(result3 === null, 'Should handle null return');
279
+ }
280
+ // Main test runner
281
+ async function runAllTests() {
282
+ console.log('🚀 Starting Comprehensive ConnectOnion Tests\n');
283
+ console.log('='.repeat(50));
284
+ try {
285
+ await testBasicToolConversion();
286
+ await testClassTools();
287
+ await testAgentCreation();
288
+ await testErrorHandling();
289
+ await testProcessTools();
290
+ await testHistoryTracking();
291
+ await testToolWithOptionalParams();
292
+ await testAsyncTools();
293
+ await testToolNaming();
294
+ await testEdgeCases();
295
+ }
296
+ catch (error) {
297
+ console.error('\n❌ Test suite failed with error:', error);
298
+ testsFailed++;
299
+ }
300
+ console.log('\n' + '='.repeat(50));
301
+ console.log('📊 Test Results:');
302
+ console.log(`✅ Passed: ${testsPassed}`);
303
+ console.log(`❌ Failed: ${testsFailed}`);
304
+ console.log(`📈 Success Rate: ${((testsPassed / (testsPassed + testsFailed)) * 100).toFixed(1)}%`);
305
+ if (testsFailed === 0) {
306
+ console.log('\n🎉 All tests passed! The SDK is working correctly.');
307
+ }
308
+ else {
309
+ console.log('\n⚠️ Some tests failed. Please review the errors above.');
310
+ process.exit(1);
311
+ }
312
+ }
313
+ // Run tests
314
+ runAllTests().catch(console.error);
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Simple Test Example
4
+ * Tests the agent with actual OpenAI API
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const src_1 = require("../src");
41
+ const dotenv = __importStar(require("dotenv"));
42
+ // Load environment variables
43
+ dotenv.config();
44
+ // Define a simple calculator tool
45
+ function add(a, b) {
46
+ /** Add two numbers together */
47
+ return a + b;
48
+ }
49
+ function multiply(a, b) {
50
+ /** Multiply two numbers */
51
+ return a * b;
52
+ }
53
+ async function main() {
54
+ console.log('Creating agent with OpenAI integration...');
55
+ try {
56
+ // Create an agent with tools
57
+ const agent = new src_1.Agent({
58
+ name: 'calculator',
59
+ tools: [add, multiply],
60
+ systemPrompt: 'You are a helpful calculator assistant. Use the provided tools to solve math problems.',
61
+ model: 'gpt-4o-mini'
62
+ });
63
+ console.log('Agent created successfully!');
64
+ console.log('Available tools:', agent.getTools().map(t => t.name).join(', '));
65
+ console.log('\nTesting calculation...');
66
+ // Test a simple calculation
67
+ const response = await agent.input('What is 15 plus 27, and then multiply the result by 2?');
68
+ console.log('\nAgent response:', response);
69
+ // Check history
70
+ const history = agent.getHistory();
71
+ console.log('\nNumber of history entries:', history.length);
72
+ console.log('\n✅ Test completed successfully!');
73
+ }
74
+ catch (error) {
75
+ console.error('❌ Error:', error);
76
+ process.exit(1);
77
+ }
78
+ }
79
+ // Run the test
80
+ main().catch(console.error);
@@ -0,0 +1,42 @@
1
+ /**
2
+ * History tracking for ConnectOnion TypeScript SDK
3
+ */
4
+ import { BehaviorEntry } from '../types';
5
+ export declare class History {
6
+ private behaviorPath;
7
+ private behaviors;
8
+ constructor(name: string);
9
+ /**
10
+ * Add an entry to the behavior history
11
+ */
12
+ add(type: BehaviorEntry['type'], data: any): void;
13
+ /**
14
+ * Add input to history
15
+ */
16
+ addInput(prompt: string): void;
17
+ /**
18
+ * Add LLM response to history
19
+ */
20
+ addLLMResponse(response: any): void;
21
+ /**
22
+ * Add tool call to history
23
+ */
24
+ addToolCall(name: string, args: any, result: any, callId: string): void;
25
+ /**
26
+ * Add output to history
27
+ */
28
+ addOutput(output: string): void;
29
+ /**
30
+ * Get all behaviors
31
+ */
32
+ getBehaviors(): BehaviorEntry[];
33
+ /**
34
+ * Clear history
35
+ */
36
+ clear(): void;
37
+ /**
38
+ * Save behaviors to file
39
+ */
40
+ private save;
41
+ }
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,OAAO;IAClB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAuB;gBAE5B,IAAI,EAAE,MAAM;IAgCxB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;IAWjD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI9B;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI;IAInC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IASvE;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,YAAY,IAAI,aAAa,EAAE;IAI/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,OAAO,CAAC,IAAI;CAWb"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ /**
3
+ * History tracking for ConnectOnion TypeScript SDK
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.History = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const os = __importStar(require("os"));
43
+ class History {
44
+ constructor(name) {
45
+ this.behaviors = [];
46
+ // Set up behavior tracking directory
47
+ const homeDir = os.homedir();
48
+ const connectonionDir = path.join(homeDir, '.connectonion', 'agents', name);
49
+ // Create directory if it doesn't exist
50
+ if (!fs.existsSync(connectonionDir)) {
51
+ fs.mkdirSync(connectonionDir, { recursive: true });
52
+ }
53
+ this.behaviorPath = path.join(connectonionDir, 'behavior.json');
54
+ // Load existing behaviors if file exists
55
+ if (fs.existsSync(this.behaviorPath)) {
56
+ try {
57
+ const data = fs.readFileSync(this.behaviorPath, 'utf-8');
58
+ const parsed = JSON.parse(data);
59
+ // Ensure behaviors is always an array
60
+ if (Array.isArray(parsed)) {
61
+ this.behaviors = parsed;
62
+ }
63
+ else {
64
+ console.warn('Behavior file does not contain an array, initializing empty');
65
+ this.behaviors = [];
66
+ }
67
+ }
68
+ catch (error) {
69
+ console.warn(`Failed to load existing behaviors: ${error}`);
70
+ this.behaviors = [];
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Add an entry to the behavior history
76
+ */
77
+ add(type, data) {
78
+ const entry = {
79
+ timestamp: new Date().toISOString(),
80
+ type,
81
+ data,
82
+ };
83
+ this.behaviors.push(entry);
84
+ this.save();
85
+ }
86
+ /**
87
+ * Add input to history
88
+ */
89
+ addInput(prompt) {
90
+ this.add('input', { prompt });
91
+ }
92
+ /**
93
+ * Add LLM response to history
94
+ */
95
+ addLLMResponse(response) {
96
+ this.add('llm_response', response);
97
+ }
98
+ /**
99
+ * Add tool call to history
100
+ */
101
+ addToolCall(name, args, result, callId) {
102
+ this.add('tool_call', {
103
+ name,
104
+ arguments: args,
105
+ result,
106
+ call_id: callId,
107
+ });
108
+ }
109
+ /**
110
+ * Add output to history
111
+ */
112
+ addOutput(output) {
113
+ this.add('output', { output });
114
+ }
115
+ /**
116
+ * Get all behaviors
117
+ */
118
+ getBehaviors() {
119
+ return this.behaviors;
120
+ }
121
+ /**
122
+ * Clear history
123
+ */
124
+ clear() {
125
+ this.behaviors = [];
126
+ this.save();
127
+ }
128
+ /**
129
+ * Save behaviors to file
130
+ */
131
+ save() {
132
+ try {
133
+ fs.writeFileSync(this.behaviorPath, JSON.stringify(this.behaviors, null, 2), 'utf-8');
134
+ }
135
+ catch (error) {
136
+ console.error(`Failed to save behaviors: ${error}`);
137
+ }
138
+ }
139
+ }
140
+ exports.History = History;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @purpose Public API entry point that exports all SDK components (Agent, LLM providers, tool utilities, trust system, types)
3
+ * @llm-note
4
+ * Dependencies: imports from [src/core/agent, src/llm/*, src/tools/*, src/trust/*, src/types] | imported by external consumers | tested by all test files
5
+ * Data flow: no runtime logic, pure re-exports → external code imports from here → provides unified API surface
6
+ * State/Effects: no state or side effects | static exports only
7
+ * Integration: exposes Agent, createLLM, all LLM providers (OpenAILLM, AnthropicLLM, GeminiLLM), tool utils (xray, processTools, etc), trust system, all types | single source of truth for SDK imports
8
+ */
9
+ export { Agent } from './core/agent';
10
+ export { createLLM, OpenAILLM, AnthropicLLM, GeminiLLM } from './llm';
11
+ export { createToolFromFunction, isClassInstance, extractMethodsFromInstance, processTools, xray, } from './tools/tool-utils';
12
+ export { trace as xrayTrace } from './tools/xray';
13
+ export { withReplay, xrayReplay, replay } from './tools/replay';
14
+ export * from './tools/email';
15
+ export * from './trust';
16
+ export * from './trust/tools';
17
+ export * from './types';
18
+ export { llmDo } from './llm/llm-do';
19
+ export { connect, RemoteAgent } from './connect';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,0BAA0B,EAC1B,YAAY,EACZ,IAAI,GACL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChE,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAE9B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * @purpose Public API entry point that exports all SDK components (Agent, LLM providers, tool utilities, trust system, types)
4
+ * @llm-note
5
+ * Dependencies: imports from [src/core/agent, src/llm/*, src/tools/*, src/trust/*, src/types] | imported by external consumers | tested by all test files
6
+ * Data flow: no runtime logic, pure re-exports → external code imports from here → provides unified API surface
7
+ * State/Effects: no state or side effects | static exports only
8
+ * Integration: exposes Agent, createLLM, all LLM providers (OpenAILLM, AnthropicLLM, GeminiLLM), tool utils (xray, processTools, etc), trust system, all types | single source of truth for SDK imports
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.RemoteAgent = exports.connect = exports.llmDo = exports.replay = exports.xrayReplay = exports.withReplay = exports.xrayTrace = exports.xray = exports.processTools = exports.extractMethodsFromInstance = exports.isClassInstance = exports.createToolFromFunction = exports.GeminiLLM = exports.AnthropicLLM = exports.OpenAILLM = exports.createLLM = exports.Agent = void 0;
26
+ var agent_1 = require("./core/agent");
27
+ Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } });
28
+ var llm_1 = require("./llm");
29
+ Object.defineProperty(exports, "createLLM", { enumerable: true, get: function () { return llm_1.createLLM; } });
30
+ Object.defineProperty(exports, "OpenAILLM", { enumerable: true, get: function () { return llm_1.OpenAILLM; } });
31
+ Object.defineProperty(exports, "AnthropicLLM", { enumerable: true, get: function () { return llm_1.AnthropicLLM; } });
32
+ Object.defineProperty(exports, "GeminiLLM", { enumerable: true, get: function () { return llm_1.GeminiLLM; } });
33
+ var tool_utils_1 = require("./tools/tool-utils");
34
+ Object.defineProperty(exports, "createToolFromFunction", { enumerable: true, get: function () { return tool_utils_1.createToolFromFunction; } });
35
+ Object.defineProperty(exports, "isClassInstance", { enumerable: true, get: function () { return tool_utils_1.isClassInstance; } });
36
+ Object.defineProperty(exports, "extractMethodsFromInstance", { enumerable: true, get: function () { return tool_utils_1.extractMethodsFromInstance; } });
37
+ Object.defineProperty(exports, "processTools", { enumerable: true, get: function () { return tool_utils_1.processTools; } });
38
+ Object.defineProperty(exports, "xray", { enumerable: true, get: function () { return tool_utils_1.xray; } });
39
+ var xray_1 = require("./tools/xray");
40
+ Object.defineProperty(exports, "xrayTrace", { enumerable: true, get: function () { return xray_1.trace; } });
41
+ var replay_1 = require("./tools/replay");
42
+ Object.defineProperty(exports, "withReplay", { enumerable: true, get: function () { return replay_1.withReplay; } });
43
+ Object.defineProperty(exports, "xrayReplay", { enumerable: true, get: function () { return replay_1.xrayReplay; } });
44
+ Object.defineProperty(exports, "replay", { enumerable: true, get: function () { return replay_1.replay; } });
45
+ __exportStar(require("./tools/email"), exports);
46
+ __exportStar(require("./trust"), exports);
47
+ __exportStar(require("./trust/tools"), exports);
48
+ __exportStar(require("./types"), exports);
49
+ var llm_do_1 = require("./llm/llm-do");
50
+ Object.defineProperty(exports, "llmDo", { enumerable: true, get: function () { return llm_do_1.llmDo; } });
51
+ var connect_1 = require("./connect");
52
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connect_1.connect; } });
53
+ Object.defineProperty(exports, "RemoteAgent", { enumerable: true, get: function () { return connect_1.RemoteAgent; } });