praisonai 1.0.19 → 1.2.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.
- package/dist/agent/context.d.ts +68 -0
- package/dist/agent/context.js +119 -0
- package/dist/agent/enhanced.d.ts +92 -0
- package/dist/agent/enhanced.js +267 -0
- package/dist/agent/handoff.d.ts +82 -0
- package/dist/agent/handoff.js +124 -0
- package/dist/agent/image.d.ts +51 -0
- package/dist/agent/image.js +93 -0
- package/dist/agent/prompt-expander.d.ts +40 -0
- package/dist/agent/prompt-expander.js +84 -0
- package/dist/agent/query-rewriter.d.ts +38 -0
- package/dist/agent/query-rewriter.js +79 -0
- package/dist/agent/research.d.ts +52 -0
- package/dist/agent/research.js +118 -0
- package/dist/agent/router.d.ts +77 -0
- package/dist/agent/router.js +113 -0
- package/dist/agent/simple.js +1 -1
- package/dist/agent/types.js +2 -2
- package/dist/auto/index.d.ts +56 -0
- package/dist/auto/index.js +142 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +150 -0
- package/dist/db/index.d.ts +23 -0
- package/dist/db/index.js +72 -0
- package/dist/db/memory-adapter.d.ts +42 -0
- package/dist/db/memory-adapter.js +146 -0
- package/dist/db/types.d.ts +113 -0
- package/dist/db/types.js +5 -0
- package/dist/eval/index.d.ts +61 -0
- package/dist/eval/index.js +157 -0
- package/dist/guardrails/index.d.ts +82 -0
- package/dist/guardrails/index.js +202 -0
- package/dist/guardrails/llm-guardrail.d.ts +40 -0
- package/dist/guardrails/llm-guardrail.js +91 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +122 -1
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +157 -0
- package/dist/knowledge/rag.d.ts +80 -0
- package/dist/knowledge/rag.js +147 -0
- package/dist/llm/openai.js +1 -1
- package/dist/llm/providers/anthropic.d.ts +33 -0
- package/dist/llm/providers/anthropic.js +291 -0
- package/dist/llm/providers/base.d.ts +25 -0
- package/dist/llm/providers/base.js +43 -0
- package/dist/llm/providers/google.d.ts +27 -0
- package/dist/llm/providers/google.js +275 -0
- package/dist/llm/providers/index.d.ts +43 -0
- package/dist/llm/providers/index.js +116 -0
- package/dist/llm/providers/openai.d.ts +18 -0
- package/dist/llm/providers/openai.js +203 -0
- package/dist/llm/providers/types.d.ts +94 -0
- package/dist/llm/providers/types.js +5 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +169 -0
- package/dist/observability/index.d.ts +86 -0
- package/dist/observability/index.js +166 -0
- package/dist/planning/index.d.ts +133 -0
- package/dist/planning/index.js +228 -0
- package/dist/session/index.d.ts +111 -0
- package/dist/session/index.js +250 -0
- package/dist/skills/index.d.ts +70 -0
- package/dist/skills/index.js +233 -0
- package/dist/telemetry/index.d.ts +102 -0
- package/dist/telemetry/index.js +187 -0
- package/dist/tools/decorator.d.ts +91 -0
- package/dist/tools/decorator.js +165 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/mcpSse.d.ts +41 -0
- package/dist/tools/mcpSse.js +108 -0
- package/dist/workflows/index.d.ts +97 -0
- package/dist/workflows/index.js +216 -0
- package/package.json +5 -2
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Planning System - Plans, Steps, and TodoLists
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PlanStorage = exports.TodoList = exports.TodoItem = exports.Plan = exports.PlanStep = void 0;
|
|
7
|
+
exports.createPlan = createPlan;
|
|
8
|
+
exports.createTodoList = createTodoList;
|
|
9
|
+
exports.createPlanStorage = createPlanStorage;
|
|
10
|
+
/**
|
|
11
|
+
* PlanStep - A single step in a plan
|
|
12
|
+
*/
|
|
13
|
+
class PlanStep {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.id = `step_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
16
|
+
this.description = config.description;
|
|
17
|
+
this.status = config.status ?? 'pending';
|
|
18
|
+
this.order = config.order ?? 0;
|
|
19
|
+
this.dependencies = config.dependencies ?? [];
|
|
20
|
+
this.metadata = config.metadata ?? {};
|
|
21
|
+
}
|
|
22
|
+
start() {
|
|
23
|
+
this.status = 'in_progress';
|
|
24
|
+
this.startedAt = Date.now();
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
complete() {
|
|
28
|
+
this.status = 'completed';
|
|
29
|
+
this.completedAt = Date.now();
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
fail() {
|
|
33
|
+
this.status = 'failed';
|
|
34
|
+
this.completedAt = Date.now();
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
cancel() {
|
|
38
|
+
this.status = 'cancelled';
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.PlanStep = PlanStep;
|
|
43
|
+
/**
|
|
44
|
+
* Plan - A collection of steps to accomplish a goal
|
|
45
|
+
*/
|
|
46
|
+
class Plan {
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.steps = [];
|
|
49
|
+
this.status = 'pending';
|
|
50
|
+
this.id = `plan_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
51
|
+
this.name = config.name;
|
|
52
|
+
this.description = config.description;
|
|
53
|
+
this.metadata = config.metadata ?? {};
|
|
54
|
+
this.createdAt = Date.now();
|
|
55
|
+
this.updatedAt = Date.now();
|
|
56
|
+
}
|
|
57
|
+
addStep(step) {
|
|
58
|
+
step.order = this.steps.length;
|
|
59
|
+
this.steps.push(step);
|
|
60
|
+
this.updatedAt = Date.now();
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
removeStep(stepId) {
|
|
64
|
+
const index = this.steps.findIndex(s => s.id === stepId);
|
|
65
|
+
if (index >= 0) {
|
|
66
|
+
this.steps.splice(index, 1);
|
|
67
|
+
this.updatedAt = Date.now();
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
getStep(stepId) {
|
|
73
|
+
return this.steps.find(s => s.id === stepId);
|
|
74
|
+
}
|
|
75
|
+
getNextStep() {
|
|
76
|
+
return this.steps.find(s => s.status === 'pending');
|
|
77
|
+
}
|
|
78
|
+
getProgress() {
|
|
79
|
+
const completed = this.steps.filter(s => s.status === 'completed').length;
|
|
80
|
+
const total = this.steps.length;
|
|
81
|
+
return {
|
|
82
|
+
completed,
|
|
83
|
+
total,
|
|
84
|
+
percentage: total > 0 ? Math.round((completed / total) * 100) : 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
start() {
|
|
88
|
+
this.status = 'in_progress';
|
|
89
|
+
this.updatedAt = Date.now();
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
complete() {
|
|
93
|
+
this.status = 'completed';
|
|
94
|
+
this.updatedAt = Date.now();
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.Plan = Plan;
|
|
99
|
+
/**
|
|
100
|
+
* TodoItem - A single todo item
|
|
101
|
+
*/
|
|
102
|
+
class TodoItem {
|
|
103
|
+
constructor(config) {
|
|
104
|
+
this.id = `todo_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
105
|
+
this.content = config.content;
|
|
106
|
+
this.priority = config.priority ?? 'medium';
|
|
107
|
+
this.status = config.status ?? 'pending';
|
|
108
|
+
this.dueDate = config.dueDate;
|
|
109
|
+
this.metadata = config.metadata ?? {};
|
|
110
|
+
this.createdAt = Date.now();
|
|
111
|
+
}
|
|
112
|
+
start() {
|
|
113
|
+
this.status = 'in_progress';
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
complete() {
|
|
117
|
+
this.status = 'completed';
|
|
118
|
+
this.completedAt = Date.now();
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
reset() {
|
|
122
|
+
this.status = 'pending';
|
|
123
|
+
this.completedAt = undefined;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.TodoItem = TodoItem;
|
|
128
|
+
/**
|
|
129
|
+
* TodoList - A collection of todo items
|
|
130
|
+
*/
|
|
131
|
+
class TodoList {
|
|
132
|
+
constructor(name = 'Todo List') {
|
|
133
|
+
this.items = [];
|
|
134
|
+
this.id = `todolist_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
135
|
+
this.name = name;
|
|
136
|
+
this.createdAt = Date.now();
|
|
137
|
+
}
|
|
138
|
+
add(item) {
|
|
139
|
+
this.items.push(item);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
remove(itemId) {
|
|
143
|
+
const index = this.items.findIndex(i => i.id === itemId);
|
|
144
|
+
if (index >= 0) {
|
|
145
|
+
this.items.splice(index, 1);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
get(itemId) {
|
|
151
|
+
return this.items.find(i => i.id === itemId);
|
|
152
|
+
}
|
|
153
|
+
getPending() {
|
|
154
|
+
return this.items.filter(i => i.status === 'pending');
|
|
155
|
+
}
|
|
156
|
+
getCompleted() {
|
|
157
|
+
return this.items.filter(i => i.status === 'completed');
|
|
158
|
+
}
|
|
159
|
+
getByPriority(priority) {
|
|
160
|
+
return this.items.filter(i => i.priority === priority);
|
|
161
|
+
}
|
|
162
|
+
getProgress() {
|
|
163
|
+
const completed = this.items.filter(i => i.status === 'completed').length;
|
|
164
|
+
const total = this.items.length;
|
|
165
|
+
return {
|
|
166
|
+
completed,
|
|
167
|
+
total,
|
|
168
|
+
percentage: total > 0 ? Math.round((completed / total) * 100) : 0
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
clear() {
|
|
172
|
+
this.items = [];
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.TodoList = TodoList;
|
|
177
|
+
/**
|
|
178
|
+
* PlanStorage - Persist plans (in-memory implementation)
|
|
179
|
+
*/
|
|
180
|
+
class PlanStorage {
|
|
181
|
+
constructor() {
|
|
182
|
+
this.plans = new Map();
|
|
183
|
+
this.todoLists = new Map();
|
|
184
|
+
}
|
|
185
|
+
savePlan(plan) {
|
|
186
|
+
this.plans.set(plan.id, plan);
|
|
187
|
+
}
|
|
188
|
+
getPlan(planId) {
|
|
189
|
+
return this.plans.get(planId);
|
|
190
|
+
}
|
|
191
|
+
deletePlan(planId) {
|
|
192
|
+
return this.plans.delete(planId);
|
|
193
|
+
}
|
|
194
|
+
listPlans() {
|
|
195
|
+
return Array.from(this.plans.values());
|
|
196
|
+
}
|
|
197
|
+
saveTodoList(list) {
|
|
198
|
+
this.todoLists.set(list.id, list);
|
|
199
|
+
}
|
|
200
|
+
getTodoList(listId) {
|
|
201
|
+
return this.todoLists.get(listId);
|
|
202
|
+
}
|
|
203
|
+
deleteTodoList(listId) {
|
|
204
|
+
return this.todoLists.delete(listId);
|
|
205
|
+
}
|
|
206
|
+
listTodoLists() {
|
|
207
|
+
return Array.from(this.todoLists.values());
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.PlanStorage = PlanStorage;
|
|
211
|
+
/**
|
|
212
|
+
* Create a Plan
|
|
213
|
+
*/
|
|
214
|
+
function createPlan(config) {
|
|
215
|
+
return new Plan(config);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Create a TodoList
|
|
219
|
+
*/
|
|
220
|
+
function createTodoList(name) {
|
|
221
|
+
return new TodoList(name);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create a PlanStorage
|
|
225
|
+
*/
|
|
226
|
+
function createPlanStorage() {
|
|
227
|
+
return new PlanStorage();
|
|
228
|
+
}
|
|
@@ -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;
|