praisonai 1.0.18 → 1.1.0

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 (55) hide show
  1. package/dist/agent/context.d.ts +68 -0
  2. package/dist/agent/context.js +119 -0
  3. package/dist/agent/enhanced.d.ts +92 -0
  4. package/dist/agent/enhanced.js +267 -0
  5. package/dist/agent/handoff.d.ts +82 -0
  6. package/dist/agent/handoff.js +124 -0
  7. package/dist/agent/router.d.ts +77 -0
  8. package/dist/agent/router.js +113 -0
  9. package/dist/agent/simple.d.ts +1 -1
  10. package/dist/agent/simple.js +40 -4
  11. package/dist/agent/types.js +2 -2
  12. package/dist/cli/index.d.ts +20 -0
  13. package/dist/cli/index.js +150 -0
  14. package/dist/db/index.d.ts +23 -0
  15. package/dist/db/index.js +72 -0
  16. package/dist/db/memory-adapter.d.ts +42 -0
  17. package/dist/db/memory-adapter.js +146 -0
  18. package/dist/db/types.d.ts +113 -0
  19. package/dist/db/types.js +5 -0
  20. package/dist/eval/index.d.ts +61 -0
  21. package/dist/eval/index.js +157 -0
  22. package/dist/guardrails/index.d.ts +82 -0
  23. package/dist/guardrails/index.js +202 -0
  24. package/dist/index.d.ts +16 -1
  25. package/dist/index.js +72 -1
  26. package/dist/knowledge/rag.d.ts +80 -0
  27. package/dist/knowledge/rag.js +147 -0
  28. package/dist/llm/openai.js +11 -3
  29. package/dist/llm/providers/anthropic.d.ts +33 -0
  30. package/dist/llm/providers/anthropic.js +291 -0
  31. package/dist/llm/providers/base.d.ts +25 -0
  32. package/dist/llm/providers/base.js +43 -0
  33. package/dist/llm/providers/google.d.ts +27 -0
  34. package/dist/llm/providers/google.js +275 -0
  35. package/dist/llm/providers/index.d.ts +43 -0
  36. package/dist/llm/providers/index.js +116 -0
  37. package/dist/llm/providers/openai.d.ts +18 -0
  38. package/dist/llm/providers/openai.js +203 -0
  39. package/dist/llm/providers/types.d.ts +94 -0
  40. package/dist/llm/providers/types.js +5 -0
  41. package/dist/observability/index.d.ts +86 -0
  42. package/dist/observability/index.js +166 -0
  43. package/dist/session/index.d.ts +111 -0
  44. package/dist/session/index.js +250 -0
  45. package/dist/skills/index.d.ts +70 -0
  46. package/dist/skills/index.js +233 -0
  47. package/dist/tools/decorator.d.ts +91 -0
  48. package/dist/tools/decorator.js +165 -0
  49. package/dist/tools/index.d.ts +2 -0
  50. package/dist/tools/index.js +3 -0
  51. package/dist/tools/mcpSse.d.ts +41 -0
  52. package/dist/tools/mcpSse.js +108 -0
  53. package/dist/workflows/index.d.ts +97 -0
  54. package/dist/workflows/index.js +216 -0
  55. package/package.json +6 -2
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * Agent Handoff - Transfer conversations between agents
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handoffFilters = exports.Handoff = void 0;
7
+ exports.handoff = handoff;
8
+ /**
9
+ * Handoff class - Represents a handoff target
10
+ */
11
+ class Handoff {
12
+ constructor(config) {
13
+ this.targetAgent = config.agent;
14
+ this.name = config.name || `handoff_to_${config.agent.name}`;
15
+ this.description = config.description || `Transfer conversation to ${config.agent.name}`;
16
+ this.condition = config.condition;
17
+ this.transformContext = config.transformContext;
18
+ }
19
+ /**
20
+ * Check if handoff should be triggered
21
+ */
22
+ shouldTrigger(context) {
23
+ if (this.condition) {
24
+ return this.condition(context);
25
+ }
26
+ return true;
27
+ }
28
+ /**
29
+ * Execute the handoff
30
+ */
31
+ async execute(context) {
32
+ let messages = context.messages;
33
+ if (this.transformContext) {
34
+ messages = this.transformContext(messages);
35
+ }
36
+ // Transfer context to target agent
37
+ const response = await this.targetAgent.chat(context.lastMessage);
38
+ return {
39
+ handedOffTo: this.targetAgent.name,
40
+ response: response.text,
41
+ context: {
42
+ ...context,
43
+ messages,
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * Get tool definition for LLM
49
+ */
50
+ getToolDefinition() {
51
+ return {
52
+ name: this.name,
53
+ description: this.description,
54
+ parameters: {
55
+ type: 'object',
56
+ properties: {
57
+ reason: {
58
+ type: 'string',
59
+ description: 'Reason for the handoff',
60
+ },
61
+ },
62
+ required: [],
63
+ },
64
+ };
65
+ }
66
+ }
67
+ exports.Handoff = Handoff;
68
+ /**
69
+ * Create a handoff configuration
70
+ */
71
+ function handoff(config) {
72
+ return new Handoff(config);
73
+ }
74
+ /**
75
+ * Handoff filters - Common condition functions
76
+ */
77
+ exports.handoffFilters = {
78
+ /**
79
+ * Trigger handoff based on topic keywords
80
+ */
81
+ topic: (keywords) => {
82
+ const keywordList = Array.isArray(keywords) ? keywords : [keywords];
83
+ return (context) => {
84
+ const lastMessage = context.lastMessage.toLowerCase();
85
+ return keywordList.some(kw => lastMessage.includes(kw.toLowerCase()));
86
+ };
87
+ },
88
+ /**
89
+ * Trigger handoff based on metadata
90
+ */
91
+ metadata: (key, value) => {
92
+ return (context) => {
93
+ return context.metadata?.[key] === value;
94
+ };
95
+ },
96
+ /**
97
+ * Always trigger
98
+ */
99
+ always: () => {
100
+ return () => true;
101
+ },
102
+ /**
103
+ * Never trigger (manual only)
104
+ */
105
+ never: () => {
106
+ return () => false;
107
+ },
108
+ /**
109
+ * Combine multiple conditions with AND
110
+ */
111
+ and: (...conditions) => {
112
+ return (context) => {
113
+ return conditions.every(cond => cond(context));
114
+ };
115
+ },
116
+ /**
117
+ * Combine multiple conditions with OR
118
+ */
119
+ or: (...conditions) => {
120
+ return (context) => {
121
+ return conditions.some(cond => cond(context));
122
+ };
123
+ },
124
+ };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Router Agent - Route requests to specialized agents
3
+ */
4
+ import type { EnhancedAgent } from './enhanced';
5
+ export interface RouteConfig {
6
+ agent: EnhancedAgent;
7
+ condition: (input: string, context?: RouteContext) => boolean | Promise<boolean>;
8
+ priority?: number;
9
+ }
10
+ export interface RouteContext {
11
+ history?: string[];
12
+ metadata?: Record<string, any>;
13
+ }
14
+ export interface RouterConfig {
15
+ name?: string;
16
+ routes: RouteConfig[];
17
+ defaultAgent?: EnhancedAgent;
18
+ verbose?: boolean;
19
+ }
20
+ /**
21
+ * Router Agent - Routes requests to the most appropriate agent
22
+ */
23
+ export declare class RouterAgent {
24
+ readonly name: string;
25
+ private routes;
26
+ private defaultAgent?;
27
+ private verbose;
28
+ constructor(config: RouterConfig);
29
+ /**
30
+ * Route a request to the appropriate agent
31
+ */
32
+ route(input: string, context?: RouteContext): Promise<{
33
+ agent: EnhancedAgent;
34
+ response: string;
35
+ } | null>;
36
+ /**
37
+ * Add a route
38
+ */
39
+ addRoute(config: RouteConfig): this;
40
+ /**
41
+ * Get all routes
42
+ */
43
+ getRoutes(): RouteConfig[];
44
+ }
45
+ /**
46
+ * Route condition helpers
47
+ */
48
+ export declare const routeConditions: {
49
+ /**
50
+ * Match by keywords
51
+ */
52
+ keywords: (keywords: string | string[]) => (input: string) => boolean;
53
+ /**
54
+ * Match by regex
55
+ */
56
+ pattern: (regex: RegExp) => (input: string) => boolean;
57
+ /**
58
+ * Match by metadata
59
+ */
60
+ metadata: (key: string, value: any) => (_input: string, context?: RouteContext) => boolean;
61
+ /**
62
+ * Always match (for default routes)
63
+ */
64
+ always: () => () => boolean;
65
+ /**
66
+ * Combine conditions with AND
67
+ */
68
+ and: (...conditions: Array<(input: string, context?: RouteContext) => boolean>) => (input: string, context?: RouteContext) => boolean;
69
+ /**
70
+ * Combine conditions with OR
71
+ */
72
+ or: (...conditions: Array<(input: string, context?: RouteContext) => boolean>) => (input: string, context?: RouteContext) => boolean;
73
+ };
74
+ /**
75
+ * Create a router agent
76
+ */
77
+ export declare function createRouter(config: RouterConfig): RouterAgent;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /**
3
+ * Router Agent - Route requests to specialized agents
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.routeConditions = exports.RouterAgent = void 0;
7
+ exports.createRouter = createRouter;
8
+ /**
9
+ * Router Agent - Routes requests to the most appropriate agent
10
+ */
11
+ class RouterAgent {
12
+ constructor(config) {
13
+ this.name = config.name || 'Router';
14
+ this.routes = config.routes.sort((a, b) => (b.priority || 0) - (a.priority || 0));
15
+ this.defaultAgent = config.defaultAgent;
16
+ this.verbose = config.verbose ?? false;
17
+ }
18
+ /**
19
+ * Route a request to the appropriate agent
20
+ */
21
+ async route(input, context) {
22
+ for (const route of this.routes) {
23
+ const matches = await route.condition(input, context);
24
+ if (matches) {
25
+ if (this.verbose) {
26
+ console.log(`[Router] Routing to: ${route.agent.name}`);
27
+ }
28
+ const response = await route.agent.chat(input);
29
+ return { agent: route.agent, response: response.text };
30
+ }
31
+ }
32
+ if (this.defaultAgent) {
33
+ if (this.verbose) {
34
+ console.log(`[Router] Using default agent: ${this.defaultAgent.name}`);
35
+ }
36
+ const response = await this.defaultAgent.chat(input);
37
+ return { agent: this.defaultAgent, response: response.text };
38
+ }
39
+ return null;
40
+ }
41
+ /**
42
+ * Add a route
43
+ */
44
+ addRoute(config) {
45
+ this.routes.push(config);
46
+ this.routes.sort((a, b) => (b.priority || 0) - (a.priority || 0));
47
+ return this;
48
+ }
49
+ /**
50
+ * Get all routes
51
+ */
52
+ getRoutes() {
53
+ return [...this.routes];
54
+ }
55
+ }
56
+ exports.RouterAgent = RouterAgent;
57
+ /**
58
+ * Route condition helpers
59
+ */
60
+ exports.routeConditions = {
61
+ /**
62
+ * Match by keywords
63
+ */
64
+ keywords: (keywords) => {
65
+ const keywordList = Array.isArray(keywords) ? keywords : [keywords];
66
+ return (input) => {
67
+ const lower = input.toLowerCase();
68
+ return keywordList.some(kw => lower.includes(kw.toLowerCase()));
69
+ };
70
+ },
71
+ /**
72
+ * Match by regex
73
+ */
74
+ pattern: (regex) => {
75
+ return (input) => regex.test(input);
76
+ },
77
+ /**
78
+ * Match by metadata
79
+ */
80
+ metadata: (key, value) => {
81
+ return (_input, context) => {
82
+ return context?.metadata?.[key] === value;
83
+ };
84
+ },
85
+ /**
86
+ * Always match (for default routes)
87
+ */
88
+ always: () => {
89
+ return () => true;
90
+ },
91
+ /**
92
+ * Combine conditions with AND
93
+ */
94
+ and: (...conditions) => {
95
+ return (input, context) => {
96
+ return conditions.every(c => c(input, context));
97
+ };
98
+ },
99
+ /**
100
+ * Combine conditions with OR
101
+ */
102
+ or: (...conditions) => {
103
+ return (input, context) => {
104
+ return conditions.some(c => c(input, context));
105
+ };
106
+ }
107
+ };
108
+ /**
109
+ * Create a router agent
110
+ */
111
+ function createRouter(config) {
112
+ return new RouterAgent(config);
113
+ }
@@ -6,7 +6,7 @@ export interface SimpleAgentConfig {
6
6
  llm?: string;
7
7
  markdown?: boolean;
8
8
  stream?: boolean;
9
- tools?: any[];
9
+ tools?: any[] | Function[];
10
10
  toolFunctions?: Record<string, Function>;
11
11
  }
12
12
  export declare class Agent {
@@ -10,7 +10,7 @@ class Agent {
10
10
  this.name = config.name || `Agent_${Math.random().toString(36).substr(2, 9)}`;
11
11
  this.verbose = config.verbose ?? process.env.PRAISON_VERBOSE !== 'false';
12
12
  this.pretty = config.pretty ?? process.env.PRAISON_PRETTY === 'true';
13
- this.llm = config.llm || 'gpt-4o-mini';
13
+ this.llm = config.llm || 'gpt-5-nano';
14
14
  this.markdown = config.markdown ?? true;
15
15
  this.stream = config.stream ?? true;
16
16
  this.tools = config.tools;
@@ -18,6 +18,40 @@ class Agent {
18
18
  // Configure logging
19
19
  logger_1.Logger.setVerbose(this.verbose);
20
20
  logger_1.Logger.setPretty(this.pretty);
21
+ // Process tools array - handle both tool definitions and functions
22
+ if (config.tools && Array.isArray(config.tools)) {
23
+ // Convert tools array to proper format if it contains functions
24
+ const processedTools = [];
25
+ for (let i = 0; i < config.tools.length; i++) {
26
+ const tool = config.tools[i];
27
+ if (typeof tool === 'function') {
28
+ // If it's a function, extract its name and register it
29
+ const funcName = tool.name || `function_${i}`;
30
+ // Skip functions with empty names
31
+ if (funcName && funcName.trim() !== '') {
32
+ this.registerToolFunction(funcName, tool);
33
+ // Auto-generate tool definition
34
+ this.addAutoGeneratedToolDefinition(funcName, tool);
35
+ }
36
+ else {
37
+ // Generate a random name for functions without names
38
+ const randomName = `function_${Math.random().toString(36).substring(2, 9)}`;
39
+ this.registerToolFunction(randomName, tool);
40
+ // Auto-generate tool definition
41
+ this.addAutoGeneratedToolDefinition(randomName, tool);
42
+ }
43
+ }
44
+ else {
45
+ // If it's already a tool definition, add it as is
46
+ processedTools.push(tool);
47
+ }
48
+ }
49
+ // Add any pre-defined tool definitions
50
+ if (processedTools.length > 0) {
51
+ this.tools = this.tools || [];
52
+ this.tools.push(...processedTools);
53
+ }
54
+ }
21
55
  // Register directly provided tool functions if any
22
56
  if (config.toolFunctions) {
23
57
  for (const [name, func] of Object.entries(config.toolFunctions)) {
@@ -69,6 +103,8 @@ class Agent {
69
103
  if (!this.tools) {
70
104
  this.tools = [];
71
105
  }
106
+ // Ensure we have a valid function name
107
+ const functionName = name || func.name || `function_${Math.random().toString(36).substring(2, 9)}`;
72
108
  // Extract parameter names from function
73
109
  const funcStr = func.toString();
74
110
  const paramMatch = funcStr.match(/\(([^)]*)\)/);
@@ -77,8 +113,8 @@ class Agent {
77
113
  const toolDef = {
78
114
  type: "function",
79
115
  function: {
80
- name,
81
- description: `Auto-generated function for ${name}`,
116
+ name: functionName,
117
+ description: `Auto-generated function for ${functionName}`,
82
118
  parameters: {
83
119
  type: "object",
84
120
  properties: {},
@@ -105,7 +141,7 @@ class Agent {
105
141
  toolDef.function.parameters.required = required;
106
142
  }
107
143
  this.tools.push(toolDef);
108
- logger_1.Logger.debug(`Auto-generated tool definition for ${name}`);
144
+ logger_1.Logger.debug(`Auto-generated tool definition for ${functionName}`);
109
145
  }
110
146
  /**
111
147
  * Process tool calls from the model
@@ -22,7 +22,7 @@ class Agent {
22
22
  this.goal = config.goal;
23
23
  this.backstory = config.backstory;
24
24
  this.verbose = config.verbose || false;
25
- this.llm = new openai_1.OpenAIService(config.llm || 'gpt-4o-mini');
25
+ this.llm = new openai_1.OpenAIService(config.llm || 'gpt-5-nano');
26
26
  this.markdown = config.markdown || true;
27
27
  this.result = '';
28
28
  logger_1.Logger.debug(`Agent created: ${this.name}`, { config });
@@ -87,7 +87,7 @@ class PraisonAIAgents {
87
87
  this.tasks = config.tasks;
88
88
  this.verbose = config.verbose || false;
89
89
  this.process = config.process || 'sequential';
90
- this.manager_llm = config.manager_llm || 'gpt-4o-mini';
90
+ this.manager_llm = config.manager_llm || 'gpt-5-nano';
91
91
  logger_1.Logger.debug('PraisonAIAgents initialized', { config });
92
92
  }
93
93
  async start() {
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PraisonAI TypeScript CLI
4
+ */
5
+ interface CLIOptions {
6
+ model?: string;
7
+ stream?: boolean;
8
+ verbose?: boolean;
9
+ sessionId?: string;
10
+ }
11
+ declare function chat(prompt: string, options?: CLIOptions): Promise<string>;
12
+ declare function listProviders(): Promise<void>;
13
+ declare function version(): Promise<void>;
14
+ declare function help(): Promise<void>;
15
+ declare function parseArgs(args: string[]): {
16
+ command: string;
17
+ prompt: string;
18
+ options: CLIOptions;
19
+ };
20
+ export { chat, listProviders, version, help, parseArgs };
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * PraisonAI TypeScript CLI
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.chat = chat;
8
+ exports.listProviders = listProviders;
9
+ exports.version = version;
10
+ exports.help = help;
11
+ exports.parseArgs = parseArgs;
12
+ const providers_1 = require("../llm/providers");
13
+ const session_1 = require("../session");
14
+ async function chat(prompt, options = {}) {
15
+ const model = options.model || process.env.PRAISONAI_MODEL || 'openai/gpt-4o-mini';
16
+ const provider = (0, providers_1.createProvider)(model);
17
+ const session = new session_1.Session({ id: options.sessionId });
18
+ session.addMessage({ role: 'user', content: prompt });
19
+ if (options.stream) {
20
+ let fullText = '';
21
+ const stream = await provider.streamText({
22
+ messages: [{ role: 'user', content: prompt }],
23
+ onToken: (token) => {
24
+ process.stdout.write(token);
25
+ fullText += token;
26
+ }
27
+ });
28
+ for await (const chunk of stream) {
29
+ // Stream is consumed by onToken
30
+ }
31
+ console.log(); // New line after streaming
32
+ return fullText;
33
+ }
34
+ else {
35
+ const result = await provider.generateText({
36
+ messages: [{ role: 'user', content: prompt }]
37
+ });
38
+ console.log(result.text);
39
+ return result.text;
40
+ }
41
+ }
42
+ async function listProviders() {
43
+ console.log('Available Providers:');
44
+ const available = (0, providers_1.getAvailableProviders)();
45
+ const providers = ['openai', 'anthropic', 'google'];
46
+ for (const p of providers) {
47
+ const status = available.includes(p) ? '✅' : '❌';
48
+ console.log(` ${status} ${p}`);
49
+ }
50
+ }
51
+ async function version() {
52
+ const pkg = require('../../package.json');
53
+ console.log(`praisonai v${pkg.version}`);
54
+ }
55
+ async function help() {
56
+ console.log(`
57
+ PraisonAI TypeScript CLI
58
+
59
+ Usage:
60
+ praisonai-ts chat <prompt> Chat with an AI agent
61
+ praisonai-ts providers List available providers
62
+ praisonai-ts version Show version
63
+ praisonai-ts help Show this help
64
+
65
+ Options:
66
+ --model, -m <model> Model to use (e.g., openai/gpt-4o-mini)
67
+ --stream, -s Enable streaming output
68
+ --verbose, -v Verbose output
69
+ --session <id> Session ID for conversation continuity
70
+
71
+ Environment Variables:
72
+ OPENAI_API_KEY OpenAI API key
73
+ ANTHROPIC_API_KEY Anthropic API key
74
+ GOOGLE_API_KEY Google API key
75
+ PRAISONAI_MODEL Default model
76
+
77
+ Examples:
78
+ praisonai-ts chat "Hello, how are you?"
79
+ praisonai-ts chat "Write a poem" --stream
80
+ praisonai-ts chat "Explain AI" -m anthropic/claude-sonnet-4-20250514
81
+ praisonai-ts providers
82
+ `);
83
+ }
84
+ function parseArgs(args) {
85
+ const options = {};
86
+ let command = 'help';
87
+ let prompt = '';
88
+ let i = 0;
89
+ while (i < args.length) {
90
+ const arg = args[i];
91
+ if (arg === '--model' || arg === '-m') {
92
+ options.model = args[++i];
93
+ }
94
+ else if (arg === '--stream' || arg === '-s') {
95
+ options.stream = true;
96
+ }
97
+ else if (arg === '--verbose' || arg === '-v') {
98
+ options.verbose = true;
99
+ }
100
+ else if (arg === '--session') {
101
+ options.sessionId = args[++i];
102
+ }
103
+ else if (!arg.startsWith('-')) {
104
+ if (!command || command === 'help') {
105
+ command = arg;
106
+ }
107
+ else {
108
+ prompt = arg;
109
+ }
110
+ }
111
+ i++;
112
+ }
113
+ return { command, prompt, options };
114
+ }
115
+ async function main() {
116
+ const args = process.argv.slice(2);
117
+ const { command, prompt, options } = parseArgs(args);
118
+ try {
119
+ switch (command) {
120
+ case 'chat':
121
+ if (!prompt) {
122
+ console.error('Error: Please provide a prompt');
123
+ process.exit(1);
124
+ }
125
+ await chat(prompt, options);
126
+ break;
127
+ case 'providers':
128
+ await listProviders();
129
+ break;
130
+ case 'version':
131
+ await version();
132
+ break;
133
+ case 'help':
134
+ default:
135
+ await help();
136
+ break;
137
+ }
138
+ }
139
+ catch (error) {
140
+ console.error('Error:', error.message);
141
+ if (options.verbose) {
142
+ console.error(error.stack);
143
+ }
144
+ process.exit(1);
145
+ }
146
+ }
147
+ // Run CLI if executed directly
148
+ if (require.main === module) {
149
+ main();
150
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Database Module - Exports for persistence layer
3
+ */
4
+ export * from './types';
5
+ export { MemoryDbAdapter } from './memory-adapter';
6
+ import type { DbAdapter, DbConfig } from './types';
7
+ /**
8
+ * Create a database adapter based on configuration
9
+ */
10
+ export declare function createDbAdapter(config: DbConfig): DbAdapter;
11
+ /**
12
+ * Get or create the default database adapter
13
+ */
14
+ export declare function getDefaultDbAdapter(): DbAdapter;
15
+ /**
16
+ * Set the default database adapter
17
+ */
18
+ export declare function setDefaultDbAdapter(adapter: DbAdapter): void;
19
+ /**
20
+ * Shortcut function for creating a database adapter
21
+ * Usage: db({ type: 'memory' }) or db({ type: 'sqlite', path: './data.db' })
22
+ */
23
+ export declare function db(config?: DbConfig): DbAdapter;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Database Module - Exports for persistence layer
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MemoryDbAdapter = void 0;
21
+ exports.createDbAdapter = createDbAdapter;
22
+ exports.getDefaultDbAdapter = getDefaultDbAdapter;
23
+ exports.setDefaultDbAdapter = setDefaultDbAdapter;
24
+ exports.db = db;
25
+ __exportStar(require("./types"), exports);
26
+ var memory_adapter_1 = require("./memory-adapter");
27
+ Object.defineProperty(exports, "MemoryDbAdapter", { enumerable: true, get: function () { return memory_adapter_1.MemoryDbAdapter; } });
28
+ const memory_adapter_2 = require("./memory-adapter");
29
+ // Default adapter instance
30
+ let defaultAdapter = null;
31
+ /**
32
+ * Create a database adapter based on configuration
33
+ */
34
+ function createDbAdapter(config) {
35
+ switch (config.type) {
36
+ case 'memory':
37
+ return new memory_adapter_2.MemoryDbAdapter();
38
+ case 'sqlite':
39
+ // SQLite adapter would be implemented here
40
+ throw new Error('SQLite adapter not yet implemented. Use memory adapter for now.');
41
+ case 'postgres':
42
+ // PostgreSQL adapter would be implemented here
43
+ throw new Error('PostgreSQL adapter not yet implemented. Use memory adapter for now.');
44
+ case 'redis':
45
+ // Redis adapter would be implemented here
46
+ throw new Error('Redis adapter not yet implemented. Use memory adapter for now.');
47
+ default:
48
+ throw new Error(`Unknown database type: ${config.type}`);
49
+ }
50
+ }
51
+ /**
52
+ * Get or create the default database adapter
53
+ */
54
+ function getDefaultDbAdapter() {
55
+ if (!defaultAdapter) {
56
+ defaultAdapter = new memory_adapter_2.MemoryDbAdapter();
57
+ }
58
+ return defaultAdapter;
59
+ }
60
+ /**
61
+ * Set the default database adapter
62
+ */
63
+ function setDefaultDbAdapter(adapter) {
64
+ defaultAdapter = adapter;
65
+ }
66
+ /**
67
+ * Shortcut function for creating a database adapter
68
+ * Usage: db({ type: 'memory' }) or db({ type: 'sqlite', path: './data.db' })
69
+ */
70
+ function db(config = { type: 'memory' }) {
71
+ return createDbAdapter(config);
72
+ }