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,58 @@
1
+ /**
2
+ * @purpose Debugging context injection system for @xray decorated tools (migrated from Python xray.py - simplified version)
3
+ * @llm-note
4
+ * Dependencies: none (leaf node) | imported by [src/core/agent.ts, src/index.ts] | tested by [examples/test-migrations.ts]
5
+ * Data flow: receives from Agent → injectXrayContext(agent, userPrompt, messages, iteration, previousTools) → stores in module-scoped xrayContext → tools access via getXrayContext() → clearXrayContext() after execution
6
+ * State/Effects: mutates module-scoped xrayContext object | no file I/O | context cleared after tool execution to prevent leakage
7
+ * Integration: exposes injectXrayContext(), clearXrayContext(), isXrayEnabled(func), getXrayContext(), trace(), XrayContext interface | used by Agent before/after tool execution | trace() displays visual execution history
8
+ * Performance: lightweight in-memory context storage | trace() uses console.error for stderr-style output
9
+ * Errors: trace() throws if no active agent context or empty execution history
10
+ */
11
+ /**
12
+ * Xray context interface - made available globally during tool execution
13
+ */
14
+ export interface XrayContext {
15
+ agent: any | null;
16
+ task: string | null;
17
+ userPrompt: string | null;
18
+ messages: any[];
19
+ iteration: number | null;
20
+ previousTools: string[];
21
+ }
22
+ /**
23
+ * Inject debugging context before tool execution
24
+ *
25
+ * Migrated from Python xray.py:430-445
26
+ *
27
+ * @param agent - The Agent instance
28
+ * @param userPrompt - Original user prompt string from agent.input()
29
+ * @param messages - Conversation history
30
+ * @param iteration - Current iteration number
31
+ * @param previousTools - List of previously called tool names
32
+ */
33
+ export declare function injectXrayContext(agent: any, userPrompt: string, messages: any[], iteration: number, previousTools: string[]): void;
34
+ /**
35
+ * Clear debugging context after tool execution
36
+ *
37
+ * Migrated from Python xray.py:448-454
38
+ */
39
+ export declare function clearXrayContext(): void;
40
+ /**
41
+ * Check if a function has the @xray decorator
42
+ *
43
+ * Migrated from Python xray.py:457-467
44
+ *
45
+ * @param func - Function to check
46
+ * @returns True if function is decorated with @xray
47
+ */
48
+ export declare function isXrayEnabled(func: any): boolean;
49
+ /**
50
+ * Get current xray context (for tools to access)
51
+ */
52
+ export declare function getXrayContext(): XrayContext;
53
+ /**
54
+ * Print a visual trace of tool execution using the current xray context.
55
+ * Throws if no active context is available.
56
+ */
57
+ export declare function trace(): void;
58
+ //# sourceMappingURL=xray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xray.d.ts","sourceRoot":"","sources":["../../src/tools/xray.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAcD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,GAAG,EAAE,EACf,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EAAE,GACtB,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAOvC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,IAAI,CA4B5B"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ /**
3
+ * @purpose Debugging context injection system for @xray decorated tools (migrated from Python xray.py - simplified version)
4
+ * @llm-note
5
+ * Dependencies: none (leaf node) | imported by [src/core/agent.ts, src/index.ts] | tested by [examples/test-migrations.ts]
6
+ * Data flow: receives from Agent → injectXrayContext(agent, userPrompt, messages, iteration, previousTools) → stores in module-scoped xrayContext → tools access via getXrayContext() → clearXrayContext() after execution
7
+ * State/Effects: mutates module-scoped xrayContext object | no file I/O | context cleared after tool execution to prevent leakage
8
+ * Integration: exposes injectXrayContext(), clearXrayContext(), isXrayEnabled(func), getXrayContext(), trace(), XrayContext interface | used by Agent before/after tool execution | trace() displays visual execution history
9
+ * Performance: lightweight in-memory context storage | trace() uses console.error for stderr-style output
10
+ * Errors: trace() throws if no active agent context or empty execution history
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.injectXrayContext = injectXrayContext;
14
+ exports.clearXrayContext = clearXrayContext;
15
+ exports.isXrayEnabled = isXrayEnabled;
16
+ exports.getXrayContext = getXrayContext;
17
+ exports.trace = trace;
18
+ /**
19
+ * Global xray context storage
20
+ */
21
+ let xrayContext = {
22
+ agent: null,
23
+ task: null,
24
+ userPrompt: null,
25
+ messages: [],
26
+ iteration: null,
27
+ previousTools: []
28
+ };
29
+ /**
30
+ * Inject debugging context before tool execution
31
+ *
32
+ * Migrated from Python xray.py:430-445
33
+ *
34
+ * @param agent - The Agent instance
35
+ * @param userPrompt - Original user prompt string from agent.input()
36
+ * @param messages - Conversation history
37
+ * @param iteration - Current iteration number
38
+ * @param previousTools - List of previously called tool names
39
+ */
40
+ function injectXrayContext(agent, userPrompt, messages, iteration, previousTools) {
41
+ xrayContext.agent = agent;
42
+ xrayContext.task = userPrompt;
43
+ xrayContext.userPrompt = userPrompt;
44
+ xrayContext.messages = messages;
45
+ xrayContext.iteration = iteration;
46
+ xrayContext.previousTools = previousTools;
47
+ }
48
+ /**
49
+ * Clear debugging context after tool execution
50
+ *
51
+ * Migrated from Python xray.py:448-454
52
+ */
53
+ function clearXrayContext() {
54
+ xrayContext.agent = null;
55
+ xrayContext.task = null;
56
+ xrayContext.userPrompt = null;
57
+ xrayContext.messages = [];
58
+ xrayContext.iteration = null;
59
+ xrayContext.previousTools = [];
60
+ }
61
+ /**
62
+ * Check if a function has the @xray decorator
63
+ *
64
+ * Migrated from Python xray.py:457-467
65
+ *
66
+ * @param func - Function to check
67
+ * @returns True if function is decorated with @xray
68
+ */
69
+ function isXrayEnabled(func) {
70
+ return func.__xray__ === true;
71
+ }
72
+ /**
73
+ * Get current xray context (for tools to access)
74
+ */
75
+ function getXrayContext() {
76
+ return xrayContext;
77
+ }
78
+ /**
79
+ * Print a visual trace of tool execution using the current xray context.
80
+ * Throws if no active context is available.
81
+ */
82
+ function trace() {
83
+ if (!xrayContext.agent) {
84
+ throw new Error('xray.trace(): no active agent context');
85
+ }
86
+ const agent = xrayContext.agent;
87
+ const task = xrayContext.task || '';
88
+ const history = agent.trace || [];
89
+ if (!Array.isArray(history) || history.length === 0) {
90
+ throw new Error('xray.trace(): no tool execution history');
91
+ }
92
+ const head = `Task: ${task}`;
93
+ // Emit compact, readable lines similar to Python output
94
+ const lines = [head, ''];
95
+ history.forEach((h, idx) => {
96
+ const ms = typeof h.timing === 'number' ? h.timing : 0;
97
+ const timeStr = ms < 100 ? `${(ms / 1000).toFixed(4)}s` : `${(ms / 1000).toFixed(1)}s`;
98
+ const argsPreview = JSON.stringify(h.args ?? {});
99
+ const shortArgs = argsPreview.length > 120 ? argsPreview.slice(0, 120) + '...' : argsPreview;
100
+ const resultStr = (h.result === undefined || h.result === null) ? '' : String(h.result);
101
+ const shortRes = resultStr.length > 120 ? resultStr.slice(0, 120) + '...' : resultStr;
102
+ const status = h.status === 'error' ? 'ERR ✗' : `• ${timeStr}`;
103
+ lines.push(`[${idx + 1}] ${status} ${h.tool_name}(${shortArgs})`);
104
+ if (shortRes)
105
+ lines.push(` OUT ← ${shortRes}`);
106
+ });
107
+ lines.push('');
108
+ // Print to stderr-style to match Console behavior
109
+ console.error(lines.join('\n'));
110
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @purpose Trust-level configuration system (open/careful/strict) with environment-based defaults and prompt templates for future trust agent integration
3
+ * @llm-note
4
+ * Dependencies: no imports (leaf node) | imported by [src/core/agent.ts] | no tests yet (configuration layer)
5
+ * Data flow: receives trust level string or object → returns trust config with level + prompt → used by Agent constructor
6
+ * State/Effects: reads env CONNECTONION_TRUST | no state mutations | pure functions
7
+ * Integration: exposes createTrustAgent(trust, apiKey, model), getDefaultTrustLevel(), getTrustPrompt(level), TrustLevel type | default level: 'careful' | prompts define trust agent behavior for future policy evaluation
8
+ * ⚠️ Trust agent not yet implemented - returns config object only | future: could return Agent instance for runtime policy checks
9
+ */
10
+ export type TrustLevel = 'open' | 'careful' | 'strict';
11
+ export declare function getDefaultTrustLevel(): TrustLevel;
12
+ export declare function getTrustPrompt(level: TrustLevel): string;
13
+ /**
14
+ * Create a trust agent or configuration object.
15
+ * For now, return a lightweight object with level and prompt.
16
+ * Future: could return an Agent instance for policy evaluation.
17
+ */
18
+ export declare function createTrustAgent(trust?: TrustLevel | {
19
+ level: TrustLevel;
20
+ prompt?: string;
21
+ }, _apiKey?: string, _model?: string): {
22
+ level: TrustLevel;
23
+ prompt: string;
24
+ name: string;
25
+ };
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trust/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAevD,wBAAgB,oBAAoB,IAAI,UAAU,CAIjD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAExD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,CAAC,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3D,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM;;;;EAMhB"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @purpose Trust-level configuration system (open/careful/strict) with environment-based defaults and prompt templates for future trust agent integration
4
+ * @llm-note
5
+ * Dependencies: no imports (leaf node) | imported by [src/core/agent.ts] | no tests yet (configuration layer)
6
+ * Data flow: receives trust level string or object → returns trust config with level + prompt → used by Agent constructor
7
+ * State/Effects: reads env CONNECTONION_TRUST | no state mutations | pure functions
8
+ * Integration: exposes createTrustAgent(trust, apiKey, model), getDefaultTrustLevel(), getTrustPrompt(level), TrustLevel type | default level: 'careful' | prompts define trust agent behavior for future policy evaluation
9
+ * ⚠️ Trust agent not yet implemented - returns config object only | future: could return Agent instance for runtime policy checks
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getDefaultTrustLevel = getDefaultTrustLevel;
13
+ exports.getTrustPrompt = getTrustPrompt;
14
+ exports.createTrustAgent = createTrustAgent;
15
+ const TRUST_PROMPTS = {
16
+ open: `You are an open trust agent for development environments.
17
+ You trust agents to enable rapid iteration and testing.
18
+ Use best effort checks but prioritize developer velocity.`,
19
+ careful: `You are a careful trust agent for staging/testing.
20
+ Verify agent identity and intent before approval:
21
+ 1) Require clear purpose, 2) Sanity-check tools, 3) Review consent.
22
+ Reject risky actions without context.`,
23
+ strict: `You are a strict trust agent for production.
24
+ Only approve actions for pre-approved agents and tools.
25
+ Enforce least privilege and strong provenance.`
26
+ };
27
+ function getDefaultTrustLevel() {
28
+ const env = (process.env.CONNECTONION_TRUST || '').toLowerCase();
29
+ if (env === 'open' || env === 'careful' || env === 'strict')
30
+ return env;
31
+ return 'careful';
32
+ }
33
+ function getTrustPrompt(level) {
34
+ return TRUST_PROMPTS[level];
35
+ }
36
+ /**
37
+ * Create a trust agent or configuration object.
38
+ * For now, return a lightweight object with level and prompt.
39
+ * Future: could return an Agent instance for policy evaluation.
40
+ */
41
+ function createTrustAgent(trust, _apiKey, _model) {
42
+ if (!trust)
43
+ trust = getDefaultTrustLevel();
44
+ const level = typeof trust === 'string' ? trust : trust.level;
45
+ const prompt = typeof trust === 'string' ? getTrustPrompt(trust) : trust.prompt || getTrustPrompt(trust.level);
46
+ return { level, prompt, name: `trust_agent_${level}` };
47
+ }
@@ -0,0 +1,4 @@
1
+ export declare function checkWhitelist(agentId: string): string;
2
+ export declare function testCapability(agentId: string, test: string, expected: string): string;
3
+ export declare function verifyAgent(agentId: string, agentInfo?: string): string;
4
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/trust/tools.ts"],"names":[],"mappings":"AAcA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAG3E"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.checkWhitelist = checkWhitelist;
37
+ exports.testCapability = testCapability;
38
+ exports.verifyAgent = verifyAgent;
39
+ /**
40
+ * @purpose Trust verification tools for whitelist checks and capability testing (minimal Python parity)
41
+ * @llm-note
42
+ * Dependencies: imports from [fs, os, path (Node.js built-ins)] | imported by [src/index.ts] | tested manually
43
+ * Data flow: checkWhitelist(agentId) → reads ~/.connectonion/trusted.txt → matches agentId against patterns (* wildcard, prefix*) → returns allow/deny string | testCapability(agentId, test, expected) → verifies expected behavior
44
+ * State/Effects: reads ~/.connectonion/trusted.txt synchronously | throws on missing file | no writes
45
+ * Integration: exposes checkWhitelist(agentId), testCapability(agentId, test, expected) | can be added as tools to trust agents | supports '*' for all and 'prefix*' for wildcards
46
+ * Performance: reads entire trusted.txt file per check | no caching | synchronous fs.readFileSync
47
+ * Errors: throws if ~/.connectonion/trusted.txt missing | pattern matching via string operations
48
+ */
49
+ const fs = __importStar(require("fs"));
50
+ const os = __importStar(require("os"));
51
+ const path = __importStar(require("path"));
52
+ function checkWhitelist(agentId) {
53
+ const file = path.join(os.homedir(), '.connectonion', 'trusted.txt');
54
+ const data = fs.readFileSync(file, 'utf-8');
55
+ const lines = data.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
56
+ const ok = lines.some(line => {
57
+ if (line === '*')
58
+ return true;
59
+ if (line.endsWith('*'))
60
+ return agentId.startsWith(line.slice(0, -1));
61
+ return line === agentId;
62
+ });
63
+ return ok ? `Whitelist: allowed (${agentId})` : `Whitelist: not found (${agentId})`;
64
+ }
65
+ function testCapability(agentId, test, expected) {
66
+ return `Capability test for ${agentId}: ${test} → expected ${expected}`;
67
+ }
68
+ function verifyAgent(agentId, agentInfo = '') {
69
+ const info = agentInfo ? ` info=${agentInfo}` : '';
70
+ return `Verification request for ${agentId}.${info}`;
71
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @purpose Core type definitions that provide compile-time safety and IDE support across the entire SDK
3
+ * @llm-note
4
+ * Dependencies: none (leaf node) | imported by [src/core/agent.ts, src/llm/*.ts, src/tools/tool-utils.ts, src/index.ts] | tested by [tests/agent.test.ts]
5
+ * Data flow: defines interfaces → used throughout codebase for type checking → no runtime data processing
6
+ * State/Effects: pure type definitions, no side effects or state
7
+ * Integration: exports all core interfaces (Tool, LLM, Agent, Message, FunctionSchema) | consumed by all modules | OpenAI-compatible message format
8
+ */
9
+ /**
10
+ * Represents a tool call request from the LLM
11
+ * @interface ToolCall
12
+ */
13
+ export interface ToolCall {
14
+ /** The name of the tool to call */
15
+ name: string;
16
+ /** Arguments to pass to the tool function */
17
+ arguments: Record<string, any>;
18
+ /** Unique identifier for this tool call */
19
+ id: string;
20
+ }
21
+ /**
22
+ * Response from an LLM completion request
23
+ * @interface LLMResponse
24
+ */
25
+ export interface LLMResponse {
26
+ /** Text content from the LLM (null if only tool calls) */
27
+ content: string | null;
28
+ /** Array of tool calls the LLM wants to make */
29
+ toolCalls: ToolCall[];
30
+ /** Raw response from the underlying API */
31
+ rawResponse: any;
32
+ }
33
+ /**
34
+ * Represents a message in the conversation history
35
+ * @interface Message
36
+ */
37
+ export interface Message {
38
+ /** The role of the message sender */
39
+ role: 'system' | 'user' | 'assistant' | 'tool';
40
+ /** The message content */
41
+ content: string;
42
+ /** Optional name for the message sender */
43
+ name?: string;
44
+ /** Tool calls made by the assistant */
45
+ tool_calls?: ToolCall[];
46
+ /** ID linking this message to a specific tool call */
47
+ tool_call_id?: string;
48
+ }
49
+ /**
50
+ * OpenAI-compatible function schema for tool definitions
51
+ * @interface FunctionSchema
52
+ */
53
+ export interface FunctionSchema {
54
+ /** The function name */
55
+ name: string;
56
+ /** Description of what the function does */
57
+ description: string;
58
+ /** JSON Schema for the function parameters */
59
+ parameters: {
60
+ /** Always 'object' for function parameters */
61
+ type: 'object';
62
+ /** Properties schema for each parameter */
63
+ properties: Record<string, any>;
64
+ /** List of required parameter names */
65
+ required?: string[];
66
+ };
67
+ }
68
+ /**
69
+ * Represents a tool that can be used by an agent
70
+ * @interface Tool
71
+ */
72
+ export interface Tool {
73
+ /** Unique name for the tool */
74
+ name: string;
75
+ /** Description of what the tool does (shown to LLM) */
76
+ description: string;
77
+ /** Function to execute the tool with given arguments */
78
+ run: (args: Record<string, any>) => Promise<any> | any;
79
+ /** Converts the tool to an OpenAI function schema */
80
+ toFunctionSchema: () => FunctionSchema;
81
+ /** Optional: mark as @xray to pause in debugger */
82
+ xray?: boolean;
83
+ }
84
+ /**
85
+ * Result from executing a tool
86
+ * @interface ToolResult
87
+ */
88
+ export interface ToolResult {
89
+ /** Status of the tool execution */
90
+ status: 'success' | 'error' | 'not_found';
91
+ /** The result value if successful */
92
+ result?: any;
93
+ /** Error message if failed */
94
+ error?: string;
95
+ }
96
+ /**
97
+ * Configuration options for creating an Agent
98
+ * @interface AgentConfig
99
+ */
100
+ export interface AgentConfig {
101
+ /** Unique name for the agent (used for behavior tracking) */
102
+ name: string;
103
+ /** Custom LLM instance (optional, defaults to OpenAI) */
104
+ llm?: LLM;
105
+ /** Array of tools available to the agent */
106
+ tools?: Tool[] | Function[] | any[];
107
+ /** System prompt defining agent behavior */
108
+ systemPrompt?: string;
109
+ /** API key for the LLM provider */
110
+ apiKey?: string;
111
+ /** Model to use (e.g., 'gpt-4o-mini') */
112
+ model?: string;
113
+ /** Maximum iterations for tool calling (default: 10) */
114
+ maxIterations?: number;
115
+ /** Trust configuration for the agent */
116
+ trust?: string | any;
117
+ /** Logging: true=./{name}.log, false=off, undefined=~/.co/logs/{name}.log, or string path */
118
+ log?: boolean | string;
119
+ }
120
+ /**
121
+ * Interface for Language Model providers
122
+ * @interface LLM
123
+ */
124
+ export interface LLM {
125
+ /**
126
+ * Complete a conversation with optional tool support
127
+ * @param messages - Conversation history
128
+ * @param tools - Available tools as function schemas
129
+ * @returns Promise resolving to the LLM response
130
+ */
131
+ complete(messages: Message[], tools?: FunctionSchema[]): Promise<LLMResponse>;
132
+ /**
133
+ * Generate structured output matching a schema.
134
+ * Provider implementations may use native structured APIs if available,
135
+ * otherwise they will prompt the model to return strict JSON and parse it.
136
+ * @param messages - Conversation history
137
+ * @param schema - JSON Schema-like object describing expected output
138
+ */
139
+ structuredComplete<T = any>(messages: Message[], schema: any): Promise<T>;
140
+ }
141
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,WAAW,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AAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC3E"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * @purpose Core type definitions that provide compile-time safety and IDE support across the entire SDK
4
+ * @llm-note
5
+ * Dependencies: none (leaf node) | imported by [src/core/agent.ts, src/llm/*.ts, src/tools/tool-utils.ts, src/index.ts] | tested by [tests/agent.test.ts]
6
+ * Data flow: defines interfaces → used throughout codebase for type checking → no runtime data processing
7
+ * State/Effects: pure type definitions, no side effects or state
8
+ * Integration: exports all core interfaces (Tool, LLM, Agent, Message, FunctionSchema) | consumed by all modules | OpenAI-compatible message format
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "connectonion",
3
+ "version": "0.0.1",
4
+ "description": "TypeScript SDK for ConnectOnion - A framework for creating AI agents with behavior tracking",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "build:examples": "tsc -p tsconfig.examples.json",
10
+ "watch": "tsc -w",
11
+ "test": "jest",
12
+ "test:watch": "jest --watch",
13
+ "test:examples": "npm run build:examples && node dist/examples/examples/test-tools.js",
14
+ "lint": "eslint src --ext .ts",
15
+ "format": "prettier --write \"src/**/*.ts\"",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "keywords": [
19
+ "ai",
20
+ "agent",
21
+ "llm",
22
+ "openai",
23
+ "tools",
24
+ "automation",
25
+ "typescript"
26
+ ],
27
+ "author": "ConnectOnion Team",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/wu-changxing/connectonion-ts"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/wu-changxing/connectonion-ts/issues"
35
+ },
36
+ "homepage": "https://github.com/wu-changxing/connectonion-ts#readme",
37
+ "dependencies": {
38
+ "@anthropic-ai/sdk": "^0.67.0",
39
+ "@google/generative-ai": "^0.24.1",
40
+ "dotenv": "^16.0.0",
41
+ "openai": "^4.0.0",
42
+ "ws": "^8.18.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/jest": "^29.0.0",
46
+ "@types/node": "^20.0.0",
47
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
48
+ "@typescript-eslint/parser": "^6.0.0",
49
+ "eslint": "^8.0.0",
50
+ "jest": "^29.0.0",
51
+ "prettier": "^3.0.0",
52
+ "ts-jest": "^29.0.0",
53
+ "typescript": "^5.0.0"
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "README.md",
58
+ "LICENSE"
59
+ ],
60
+ "engines": {
61
+ "node": ">=16.0.0"
62
+ }
63
+ }