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,166 @@
1
+ "use strict";
2
+ /**
3
+ * Observability - Tracing, logging, and metrics hooks
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConsoleObservabilityAdapter = exports.MemoryObservabilityAdapter = void 0;
7
+ exports.setObservabilityAdapter = setObservabilityAdapter;
8
+ exports.getObservabilityAdapter = getObservabilityAdapter;
9
+ /**
10
+ * In-memory observability adapter for development
11
+ */
12
+ class MemoryObservabilityAdapter {
13
+ constructor() {
14
+ this.traces = new Map();
15
+ this.spans = new Map();
16
+ }
17
+ startTrace(name, metadata = {}) {
18
+ const traceId = this.generateId();
19
+ const trace = {
20
+ id: traceId,
21
+ name,
22
+ startTime: Date.now(),
23
+ status: 'running',
24
+ spans: [],
25
+ metadata
26
+ };
27
+ this.traces.set(traceId, trace);
28
+ const self = this;
29
+ return {
30
+ traceId,
31
+ startSpan(spanName, kind) {
32
+ return self.startSpan(traceId, spanName, kind);
33
+ },
34
+ end(status = 'completed') {
35
+ self.endTrace(traceId, status);
36
+ }
37
+ };
38
+ }
39
+ endTrace(traceId, status = 'completed') {
40
+ const trace = this.traces.get(traceId);
41
+ if (trace) {
42
+ trace.endTime = Date.now();
43
+ trace.status = status;
44
+ }
45
+ }
46
+ startSpan(traceId, name, kind, parentId) {
47
+ const spanId = this.generateId();
48
+ const span = {
49
+ id: spanId,
50
+ traceId,
51
+ parentId,
52
+ name,
53
+ kind,
54
+ status: 'running',
55
+ startTime: Date.now(),
56
+ attributes: {},
57
+ events: []
58
+ };
59
+ this.spans.set(spanId, span);
60
+ const trace = this.traces.get(traceId);
61
+ if (trace) {
62
+ trace.spans.push(span);
63
+ }
64
+ const self = this;
65
+ return {
66
+ spanId,
67
+ traceId,
68
+ addEvent(eventName, attributes) {
69
+ self.addEvent(spanId, eventName, attributes);
70
+ },
71
+ setAttributes(attributes) {
72
+ const s = self.spans.get(spanId);
73
+ if (s) {
74
+ s.attributes = { ...s.attributes, ...attributes };
75
+ }
76
+ },
77
+ end(status = 'completed') {
78
+ self.endSpan(spanId, status);
79
+ }
80
+ };
81
+ }
82
+ endSpan(spanId, status = 'completed', attributes) {
83
+ const span = this.spans.get(spanId);
84
+ if (span) {
85
+ span.endTime = Date.now();
86
+ span.status = status;
87
+ if (attributes) {
88
+ span.attributes = { ...span.attributes, ...attributes };
89
+ }
90
+ }
91
+ }
92
+ addEvent(spanId, name, attributes) {
93
+ const span = this.spans.get(spanId);
94
+ if (span) {
95
+ span.events.push({
96
+ name,
97
+ timestamp: Date.now(),
98
+ attributes
99
+ });
100
+ }
101
+ }
102
+ async flush() {
103
+ // No-op for memory adapter
104
+ }
105
+ // Utility methods
106
+ getTrace(traceId) {
107
+ return this.traces.get(traceId);
108
+ }
109
+ getSpan(spanId) {
110
+ return this.spans.get(spanId);
111
+ }
112
+ getAllTraces() {
113
+ return Array.from(this.traces.values());
114
+ }
115
+ clear() {
116
+ this.traces.clear();
117
+ this.spans.clear();
118
+ }
119
+ generateId() {
120
+ return Math.random().toString(36).substring(2, 15);
121
+ }
122
+ }
123
+ exports.MemoryObservabilityAdapter = MemoryObservabilityAdapter;
124
+ /**
125
+ * Console observability adapter for debugging
126
+ */
127
+ class ConsoleObservabilityAdapter {
128
+ constructor() {
129
+ this.memory = new MemoryObservabilityAdapter();
130
+ }
131
+ startTrace(name, metadata) {
132
+ console.log(`[TRACE START] ${name}`, metadata || '');
133
+ return this.memory.startTrace(name, metadata);
134
+ }
135
+ endTrace(traceId, status) {
136
+ console.log(`[TRACE END] ${traceId} - ${status || 'completed'}`);
137
+ this.memory.endTrace(traceId, status);
138
+ }
139
+ startSpan(traceId, name, kind, parentId) {
140
+ console.log(` [SPAN START] ${name} (${kind})`);
141
+ return this.memory.startSpan(traceId, name, kind, parentId);
142
+ }
143
+ endSpan(spanId, status, attributes) {
144
+ console.log(` [SPAN END] ${spanId} - ${status || 'completed'}`, attributes || '');
145
+ this.memory.endSpan(spanId, status, attributes);
146
+ }
147
+ addEvent(spanId, name, attributes) {
148
+ console.log(` [EVENT] ${name}`, attributes || '');
149
+ this.memory.addEvent(spanId, name, attributes);
150
+ }
151
+ async flush() {
152
+ await this.memory.flush();
153
+ }
154
+ }
155
+ exports.ConsoleObservabilityAdapter = ConsoleObservabilityAdapter;
156
+ // Global observability instance
157
+ let globalAdapter = null;
158
+ function setObservabilityAdapter(adapter) {
159
+ globalAdapter = adapter;
160
+ }
161
+ function getObservabilityAdapter() {
162
+ if (!globalAdapter) {
163
+ globalAdapter = new MemoryObservabilityAdapter();
164
+ }
165
+ return globalAdapter;
166
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Session Management - Session, Run, and Trace tracking
3
+ */
4
+ export interface SessionConfig {
5
+ id?: string;
6
+ metadata?: Record<string, any>;
7
+ }
8
+ export interface RunConfig {
9
+ id?: string;
10
+ metadata?: Record<string, any>;
11
+ }
12
+ export interface TraceConfig {
13
+ id?: string;
14
+ name: string;
15
+ attributes?: Record<string, any>;
16
+ }
17
+ export type RunStatus = 'pending' | 'running' | 'completed' | 'failed';
18
+ export type TraceStatus = 'pending' | 'running' | 'completed' | 'failed';
19
+ export interface Message {
20
+ id: string;
21
+ role: 'system' | 'user' | 'assistant' | 'tool';
22
+ content: string | null;
23
+ name?: string;
24
+ tool_call_id?: string;
25
+ tool_calls?: any[];
26
+ timestamp: number;
27
+ runId?: string;
28
+ }
29
+ /**
30
+ * Trace represents a span within a run (e.g., LLM call, tool call)
31
+ */
32
+ export declare class Trace {
33
+ readonly id: string;
34
+ readonly runId: string;
35
+ readonly name: string;
36
+ readonly parentId: string | null;
37
+ readonly startTime: number;
38
+ endTime: number | null;
39
+ status: TraceStatus;
40
+ attributes: Record<string, any>;
41
+ private children;
42
+ constructor(runId: string, config: TraceConfig, parentId?: string | null);
43
+ start(): this;
44
+ complete(attributes?: Record<string, any>): this;
45
+ fail(error?: Error): this;
46
+ get duration(): number | null;
47
+ createChild(config: TraceConfig): Trace;
48
+ getChildren(): Trace[];
49
+ toJSON(): Record<string, any>;
50
+ }
51
+ /**
52
+ * Run represents a single execution within a session (e.g., one chat call)
53
+ */
54
+ export declare class Run {
55
+ readonly id: string;
56
+ readonly sessionId: string;
57
+ readonly startTime: number;
58
+ endTime: number | null;
59
+ status: RunStatus;
60
+ error: Error | null;
61
+ metadata: Record<string, any>;
62
+ private traces;
63
+ private messages;
64
+ constructor(sessionId: string, config?: RunConfig);
65
+ start(): this;
66
+ complete(metadata?: Record<string, any>): this;
67
+ fail(error: Error): this;
68
+ get duration(): number | null;
69
+ createTrace(config: TraceConfig): Trace;
70
+ addMessage(message: Omit<Message, 'id' | 'timestamp' | 'runId'>): Message;
71
+ getTraces(): Trace[];
72
+ getMessages(): Message[];
73
+ toJSON(): Record<string, any>;
74
+ }
75
+ /**
76
+ * Session represents a conversation session with message history
77
+ */
78
+ export declare class Session {
79
+ readonly id: string;
80
+ readonly createdAt: number;
81
+ metadata: Record<string, any>;
82
+ private _runs;
83
+ private _messages;
84
+ constructor(config?: SessionConfig);
85
+ createRun(config?: RunConfig): Run;
86
+ get runs(): Run[];
87
+ get messages(): Message[];
88
+ addMessage(message: Omit<Message, 'id' | 'timestamp'>): Message;
89
+ getMessagesForLLM(): Array<{
90
+ role: string;
91
+ content: string | null;
92
+ tool_call_id?: string;
93
+ tool_calls?: any[];
94
+ }>;
95
+ clearMessages(): void;
96
+ toJSON(): Record<string, any>;
97
+ }
98
+ /**
99
+ * SessionManager for managing multiple sessions
100
+ */
101
+ export declare class SessionManager {
102
+ private sessions;
103
+ create(config?: SessionConfig): Session;
104
+ get(id: string): Session | undefined;
105
+ getOrCreate(id: string, config?: Omit<SessionConfig, 'id'>): Session;
106
+ list(): Session[];
107
+ delete(id: string): boolean;
108
+ clear(): void;
109
+ toJSON(): Record<string, any>;
110
+ }
111
+ export declare function getSessionManager(): SessionManager;
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ /**
3
+ * Session Management - Session, Run, and Trace tracking
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SessionManager = exports.Session = exports.Run = exports.Trace = void 0;
7
+ exports.getSessionManager = getSessionManager;
8
+ const crypto_1 = require("crypto");
9
+ /**
10
+ * Trace represents a span within a run (e.g., LLM call, tool call)
11
+ */
12
+ class Trace {
13
+ constructor(runId, config, parentId = null) {
14
+ this.endTime = null;
15
+ this.status = 'pending';
16
+ this.children = [];
17
+ this.id = config.id || (0, crypto_1.randomUUID)();
18
+ this.runId = runId;
19
+ this.name = config.name;
20
+ this.parentId = parentId;
21
+ this.startTime = Date.now();
22
+ this.attributes = config.attributes || {};
23
+ }
24
+ start() {
25
+ this.status = 'running';
26
+ return this;
27
+ }
28
+ complete(attributes) {
29
+ this.status = 'completed';
30
+ this.endTime = Date.now();
31
+ if (attributes) {
32
+ this.attributes = { ...this.attributes, ...attributes };
33
+ }
34
+ return this;
35
+ }
36
+ fail(error) {
37
+ this.status = 'failed';
38
+ this.endTime = Date.now();
39
+ if (error) {
40
+ this.attributes.error = error.message;
41
+ this.attributes.errorStack = error.stack;
42
+ }
43
+ return this;
44
+ }
45
+ get duration() {
46
+ if (this.endTime === null)
47
+ return null;
48
+ return this.endTime - this.startTime;
49
+ }
50
+ createChild(config) {
51
+ const child = new Trace(this.runId, config, this.id);
52
+ this.children.push(child);
53
+ return child;
54
+ }
55
+ getChildren() {
56
+ return [...this.children];
57
+ }
58
+ toJSON() {
59
+ return {
60
+ id: this.id,
61
+ runId: this.runId,
62
+ name: this.name,
63
+ parentId: this.parentId,
64
+ startTime: this.startTime,
65
+ endTime: this.endTime,
66
+ duration: this.duration,
67
+ status: this.status,
68
+ attributes: this.attributes,
69
+ children: this.children.map(c => c.toJSON()),
70
+ };
71
+ }
72
+ }
73
+ exports.Trace = Trace;
74
+ /**
75
+ * Run represents a single execution within a session (e.g., one chat call)
76
+ */
77
+ class Run {
78
+ constructor(sessionId, config = {}) {
79
+ this.endTime = null;
80
+ this.status = 'pending';
81
+ this.error = null;
82
+ this.traces = [];
83
+ this.messages = [];
84
+ this.id = config.id || (0, crypto_1.randomUUID)();
85
+ this.sessionId = sessionId;
86
+ this.startTime = Date.now();
87
+ this.metadata = config.metadata || {};
88
+ }
89
+ start() {
90
+ this.status = 'running';
91
+ return this;
92
+ }
93
+ complete(metadata) {
94
+ this.status = 'completed';
95
+ this.endTime = Date.now();
96
+ if (metadata) {
97
+ this.metadata = { ...this.metadata, ...metadata };
98
+ }
99
+ return this;
100
+ }
101
+ fail(error) {
102
+ this.status = 'failed';
103
+ this.endTime = Date.now();
104
+ this.error = error;
105
+ return this;
106
+ }
107
+ get duration() {
108
+ if (this.endTime === null)
109
+ return null;
110
+ return this.endTime - this.startTime;
111
+ }
112
+ createTrace(config) {
113
+ const trace = new Trace(this.id, config);
114
+ this.traces.push(trace);
115
+ return trace;
116
+ }
117
+ addMessage(message) {
118
+ const msg = {
119
+ ...message,
120
+ id: (0, crypto_1.randomUUID)(),
121
+ timestamp: Date.now(),
122
+ runId: this.id,
123
+ };
124
+ this.messages.push(msg);
125
+ return msg;
126
+ }
127
+ getTraces() {
128
+ return [...this.traces];
129
+ }
130
+ getMessages() {
131
+ return [...this.messages];
132
+ }
133
+ toJSON() {
134
+ return {
135
+ id: this.id,
136
+ sessionId: this.sessionId,
137
+ startTime: this.startTime,
138
+ endTime: this.endTime,
139
+ duration: this.duration,
140
+ status: this.status,
141
+ error: this.error?.message,
142
+ metadata: this.metadata,
143
+ traces: this.traces.map(t => t.toJSON()),
144
+ messageCount: this.messages.length,
145
+ };
146
+ }
147
+ }
148
+ exports.Run = Run;
149
+ /**
150
+ * Session represents a conversation session with message history
151
+ */
152
+ class Session {
153
+ constructor(config = {}) {
154
+ this._runs = [];
155
+ this._messages = [];
156
+ this.id = config.id || (0, crypto_1.randomUUID)();
157
+ this.createdAt = Date.now();
158
+ this.metadata = config.metadata || {};
159
+ }
160
+ createRun(config = {}) {
161
+ const run = new Run(this.id, config);
162
+ this._runs.push(run);
163
+ return run;
164
+ }
165
+ get runs() {
166
+ return [...this._runs];
167
+ }
168
+ get messages() {
169
+ return [...this._messages];
170
+ }
171
+ addMessage(message) {
172
+ const msg = {
173
+ ...message,
174
+ id: (0, crypto_1.randomUUID)(),
175
+ timestamp: Date.now(),
176
+ };
177
+ this._messages.push(msg);
178
+ return msg;
179
+ }
180
+ getMessagesForLLM() {
181
+ return this._messages.map(m => ({
182
+ role: m.role,
183
+ content: m.content,
184
+ ...(m.tool_call_id ? { tool_call_id: m.tool_call_id } : {}),
185
+ ...(m.tool_calls ? { tool_calls: m.tool_calls } : {}),
186
+ }));
187
+ }
188
+ clearMessages() {
189
+ this._messages = [];
190
+ }
191
+ toJSON() {
192
+ return {
193
+ id: this.id,
194
+ createdAt: this.createdAt,
195
+ metadata: this.metadata,
196
+ runCount: this._runs.length,
197
+ messageCount: this._messages.length,
198
+ runs: this._runs.map(r => r.toJSON()),
199
+ };
200
+ }
201
+ }
202
+ exports.Session = Session;
203
+ /**
204
+ * SessionManager for managing multiple sessions
205
+ */
206
+ class SessionManager {
207
+ constructor() {
208
+ this.sessions = new Map();
209
+ }
210
+ create(config = {}) {
211
+ const session = new Session(config);
212
+ this.sessions.set(session.id, session);
213
+ return session;
214
+ }
215
+ get(id) {
216
+ return this.sessions.get(id);
217
+ }
218
+ getOrCreate(id, config = {}) {
219
+ let session = this.sessions.get(id);
220
+ if (!session) {
221
+ session = new Session({ ...config, id });
222
+ this.sessions.set(id, session);
223
+ }
224
+ return session;
225
+ }
226
+ list() {
227
+ return Array.from(this.sessions.values());
228
+ }
229
+ delete(id) {
230
+ return this.sessions.delete(id);
231
+ }
232
+ clear() {
233
+ this.sessions.clear();
234
+ }
235
+ toJSON() {
236
+ return {
237
+ sessionCount: this.sessions.size,
238
+ sessions: this.list().map(s => s.toJSON()),
239
+ };
240
+ }
241
+ }
242
+ exports.SessionManager = SessionManager;
243
+ // Default session manager instance
244
+ let defaultManager = null;
245
+ function getSessionManager() {
246
+ if (!defaultManager) {
247
+ defaultManager = new SessionManager();
248
+ }
249
+ return defaultManager;
250
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Skills System - Agent Skills standard implementation
3
+ */
4
+ export interface SkillMetadata {
5
+ name: string;
6
+ description: string;
7
+ license?: string;
8
+ compatibility?: string;
9
+ allowedTools?: string[];
10
+ metadata?: Record<string, string>;
11
+ }
12
+ export interface Skill {
13
+ metadata: SkillMetadata;
14
+ instructions: string;
15
+ path?: string;
16
+ }
17
+ export interface SkillDiscoveryOptions {
18
+ paths?: string[];
19
+ includeSystem?: boolean;
20
+ includeUser?: boolean;
21
+ includeProject?: boolean;
22
+ }
23
+ /**
24
+ * Parse SKILL.md file
25
+ */
26
+ export declare function parseSkillFile(content: string): Skill;
27
+ /**
28
+ * Skill Manager - Load and manage skills
29
+ */
30
+ export declare class SkillManager {
31
+ private skills;
32
+ private discoveryPaths;
33
+ constructor(options?: SkillDiscoveryOptions);
34
+ private setupDiscoveryPaths;
35
+ /**
36
+ * Discover and load skills from configured paths
37
+ */
38
+ discover(): Promise<Skill[]>;
39
+ /**
40
+ * Load a skill from a SKILL.md file
41
+ */
42
+ loadSkill(skillPath: string): Promise<Skill>;
43
+ /**
44
+ * Register a skill manually
45
+ */
46
+ register(skill: Skill): void;
47
+ /**
48
+ * Get a skill by name
49
+ */
50
+ get(name: string): Skill | undefined;
51
+ /**
52
+ * List all loaded skills
53
+ */
54
+ list(): Skill[];
55
+ /**
56
+ * Generate XML prompt for skills
57
+ */
58
+ generatePrompt(skillNames?: string[]): string;
59
+ /**
60
+ * Validate a skill
61
+ */
62
+ validate(skill: Skill): {
63
+ valid: boolean;
64
+ errors: string[];
65
+ };
66
+ }
67
+ /**
68
+ * Create a skill manager
69
+ */
70
+ export declare function createSkillManager(options?: SkillDiscoveryOptions): SkillManager;