praisonai 1.1.0 → 1.2.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.
- 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/auto/index.d.ts +56 -0
- package/dist/auto/index.js +142 -0
- package/dist/guardrails/llm-guardrail.d.ts +40 -0
- package/dist/guardrails/llm-guardrail.js +91 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +54 -1
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +157 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +169 -0
- package/dist/planning/index.d.ts +133 -0
- package/dist/planning/index.js +228 -0
- package/dist/telemetry/index.d.ts +102 -0
- package/dist/telemetry/index.js +187 -0
- package/dist/tools/arxivTools.d.ts +19 -6
- package/dist/tools/arxivTools.js +13 -7
- package/dist/tools/base.d.ts +97 -0
- package/dist/tools/base.js +147 -0
- package/dist/tools/index.d.ts +1 -11
- package/dist/tools/index.js +7 -11
- package/dist/tools/mcpSse.d.ts +5 -3
- package/dist/tools/mcpSse.js +6 -4
- package/package.json +1 -2
package/dist/memory/memory.js
CHANGED
|
@@ -1 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory System - Conversation and context memory management
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Memory = void 0;
|
|
7
|
+
exports.createMemory = createMemory;
|
|
8
|
+
/**
|
|
9
|
+
* Memory class for managing conversation history and context
|
|
10
|
+
*/
|
|
11
|
+
class Memory {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
this.entries = new Map();
|
|
14
|
+
this.maxEntries = config.maxEntries ?? 1000;
|
|
15
|
+
this.maxTokens = config.maxTokens ?? 100000;
|
|
16
|
+
this.embeddingProvider = config.embeddingProvider;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Add a memory entry
|
|
20
|
+
*/
|
|
21
|
+
async add(content, role, metadata) {
|
|
22
|
+
const id = this.generateId();
|
|
23
|
+
const entry = {
|
|
24
|
+
id,
|
|
25
|
+
content,
|
|
26
|
+
role,
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
metadata
|
|
29
|
+
};
|
|
30
|
+
if (this.embeddingProvider) {
|
|
31
|
+
entry.embedding = await this.embeddingProvider.embed(content);
|
|
32
|
+
}
|
|
33
|
+
this.entries.set(id, entry);
|
|
34
|
+
this.enforceLimit();
|
|
35
|
+
return entry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get a memory entry by ID
|
|
39
|
+
*/
|
|
40
|
+
get(id) {
|
|
41
|
+
return this.entries.get(id);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get all entries
|
|
45
|
+
*/
|
|
46
|
+
getAll() {
|
|
47
|
+
return Array.from(this.entries.values())
|
|
48
|
+
.sort((a, b) => a.timestamp - b.timestamp);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get recent entries
|
|
52
|
+
*/
|
|
53
|
+
getRecent(count) {
|
|
54
|
+
return this.getAll().slice(-count);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Search memory by text similarity
|
|
58
|
+
*/
|
|
59
|
+
async search(query, limit = 5) {
|
|
60
|
+
if (!this.embeddingProvider) {
|
|
61
|
+
// Fallback to simple text matching
|
|
62
|
+
return this.textSearch(query, limit);
|
|
63
|
+
}
|
|
64
|
+
const queryEmbedding = await this.embeddingProvider.embed(query);
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const entry of this.entries.values()) {
|
|
67
|
+
if (entry.embedding) {
|
|
68
|
+
const score = this.cosineSimilarity(queryEmbedding, entry.embedding);
|
|
69
|
+
results.push({ entry, score });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return results
|
|
73
|
+
.sort((a, b) => b.score - a.score)
|
|
74
|
+
.slice(0, limit);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Simple text search fallback
|
|
78
|
+
*/
|
|
79
|
+
textSearch(query, limit) {
|
|
80
|
+
const queryLower = query.toLowerCase();
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const entry of this.entries.values()) {
|
|
83
|
+
const contentLower = entry.content.toLowerCase();
|
|
84
|
+
if (contentLower.includes(queryLower)) {
|
|
85
|
+
const score = queryLower.length / contentLower.length;
|
|
86
|
+
results.push({ entry, score: Math.min(score * 10, 1) });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return results
|
|
90
|
+
.sort((a, b) => b.score - a.score)
|
|
91
|
+
.slice(0, limit);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Calculate cosine similarity
|
|
95
|
+
*/
|
|
96
|
+
cosineSimilarity(a, b) {
|
|
97
|
+
if (a.length !== b.length)
|
|
98
|
+
return 0;
|
|
99
|
+
let dotProduct = 0;
|
|
100
|
+
let normA = 0;
|
|
101
|
+
let normB = 0;
|
|
102
|
+
for (let i = 0; i < a.length; i++) {
|
|
103
|
+
dotProduct += a[i] * b[i];
|
|
104
|
+
normA += a[i] * a[i];
|
|
105
|
+
normB += b[i] * b[i];
|
|
106
|
+
}
|
|
107
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
108
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Delete a memory entry
|
|
112
|
+
*/
|
|
113
|
+
delete(id) {
|
|
114
|
+
return this.entries.delete(id);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Clear all memory
|
|
118
|
+
*/
|
|
119
|
+
clear() {
|
|
120
|
+
this.entries.clear();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get memory size
|
|
124
|
+
*/
|
|
125
|
+
get size() {
|
|
126
|
+
return this.entries.size;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build context string from recent memory
|
|
130
|
+
*/
|
|
131
|
+
buildContext(count) {
|
|
132
|
+
const entries = count ? this.getRecent(count) : this.getAll();
|
|
133
|
+
return entries
|
|
134
|
+
.map(e => `${e.role}: ${e.content}`)
|
|
135
|
+
.join('\n');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Export memory to JSON
|
|
139
|
+
*/
|
|
140
|
+
toJSON() {
|
|
141
|
+
return this.getAll();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Import memory from JSON
|
|
145
|
+
*/
|
|
146
|
+
fromJSON(entries) {
|
|
147
|
+
this.entries.clear();
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
this.entries.set(entry.id, entry);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
generateId() {
|
|
153
|
+
return `mem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
154
|
+
}
|
|
155
|
+
enforceLimit() {
|
|
156
|
+
while (this.entries.size > this.maxEntries) {
|
|
157
|
+
const oldest = this.getAll()[0];
|
|
158
|
+
if (oldest) {
|
|
159
|
+
this.entries.delete(oldest.id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.Memory = Memory;
|
|
165
|
+
/**
|
|
166
|
+
* Create a memory instance
|
|
167
|
+
*/
|
|
168
|
+
function createMemory(config) {
|
|
169
|
+
return new Memory(config);
|
|
170
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning System - Plans, Steps, and TodoLists
|
|
3
|
+
*/
|
|
4
|
+
export type PlanStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled';
|
|
5
|
+
export type TodoStatus = 'pending' | 'in_progress' | 'completed';
|
|
6
|
+
export interface PlanConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export interface PlanStepConfig {
|
|
12
|
+
description: string;
|
|
13
|
+
status?: PlanStatus;
|
|
14
|
+
order?: number;
|
|
15
|
+
dependencies?: string[];
|
|
16
|
+
metadata?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export interface TodoItemConfig {
|
|
19
|
+
content: string;
|
|
20
|
+
priority?: 'low' | 'medium' | 'high';
|
|
21
|
+
status?: TodoStatus;
|
|
22
|
+
dueDate?: Date;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* PlanStep - A single step in a plan
|
|
27
|
+
*/
|
|
28
|
+
export declare class PlanStep {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
description: string;
|
|
31
|
+
status: PlanStatus;
|
|
32
|
+
order: number;
|
|
33
|
+
dependencies: string[];
|
|
34
|
+
metadata: Record<string, any>;
|
|
35
|
+
startedAt?: number;
|
|
36
|
+
completedAt?: number;
|
|
37
|
+
constructor(config: PlanStepConfig);
|
|
38
|
+
start(): this;
|
|
39
|
+
complete(): this;
|
|
40
|
+
fail(): this;
|
|
41
|
+
cancel(): this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Plan - A collection of steps to accomplish a goal
|
|
45
|
+
*/
|
|
46
|
+
export declare class Plan {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
steps: PlanStep[];
|
|
51
|
+
status: PlanStatus;
|
|
52
|
+
metadata: Record<string, any>;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
updatedAt: number;
|
|
55
|
+
constructor(config: PlanConfig);
|
|
56
|
+
addStep(step: PlanStep): this;
|
|
57
|
+
removeStep(stepId: string): boolean;
|
|
58
|
+
getStep(stepId: string): PlanStep | undefined;
|
|
59
|
+
getNextStep(): PlanStep | undefined;
|
|
60
|
+
getProgress(): {
|
|
61
|
+
completed: number;
|
|
62
|
+
total: number;
|
|
63
|
+
percentage: number;
|
|
64
|
+
};
|
|
65
|
+
start(): this;
|
|
66
|
+
complete(): this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* TodoItem - A single todo item
|
|
70
|
+
*/
|
|
71
|
+
export declare class TodoItem {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
content: string;
|
|
74
|
+
priority: 'low' | 'medium' | 'high';
|
|
75
|
+
status: TodoStatus;
|
|
76
|
+
dueDate?: Date;
|
|
77
|
+
metadata: Record<string, any>;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
completedAt?: number;
|
|
80
|
+
constructor(config: TodoItemConfig);
|
|
81
|
+
start(): this;
|
|
82
|
+
complete(): this;
|
|
83
|
+
reset(): this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* TodoList - A collection of todo items
|
|
87
|
+
*/
|
|
88
|
+
export declare class TodoList {
|
|
89
|
+
readonly id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
items: TodoItem[];
|
|
92
|
+
createdAt: number;
|
|
93
|
+
constructor(name?: string);
|
|
94
|
+
add(item: TodoItem): this;
|
|
95
|
+
remove(itemId: string): boolean;
|
|
96
|
+
get(itemId: string): TodoItem | undefined;
|
|
97
|
+
getPending(): TodoItem[];
|
|
98
|
+
getCompleted(): TodoItem[];
|
|
99
|
+
getByPriority(priority: 'low' | 'medium' | 'high'): TodoItem[];
|
|
100
|
+
getProgress(): {
|
|
101
|
+
completed: number;
|
|
102
|
+
total: number;
|
|
103
|
+
percentage: number;
|
|
104
|
+
};
|
|
105
|
+
clear(): this;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* PlanStorage - Persist plans (in-memory implementation)
|
|
109
|
+
*/
|
|
110
|
+
export declare class PlanStorage {
|
|
111
|
+
private plans;
|
|
112
|
+
private todoLists;
|
|
113
|
+
savePlan(plan: Plan): void;
|
|
114
|
+
getPlan(planId: string): Plan | undefined;
|
|
115
|
+
deletePlan(planId: string): boolean;
|
|
116
|
+
listPlans(): Plan[];
|
|
117
|
+
saveTodoList(list: TodoList): void;
|
|
118
|
+
getTodoList(listId: string): TodoList | undefined;
|
|
119
|
+
deleteTodoList(listId: string): boolean;
|
|
120
|
+
listTodoLists(): TodoList[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a Plan
|
|
124
|
+
*/
|
|
125
|
+
export declare function createPlan(config: PlanConfig): Plan;
|
|
126
|
+
/**
|
|
127
|
+
* Create a TodoList
|
|
128
|
+
*/
|
|
129
|
+
export declare function createTodoList(name?: string): TodoList;
|
|
130
|
+
/**
|
|
131
|
+
* Create a PlanStorage
|
|
132
|
+
*/
|
|
133
|
+
export declare function createPlanStorage(): PlanStorage;
|
|
@@ -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,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry - Usage tracking and analytics
|
|
3
|
+
*/
|
|
4
|
+
export interface TelemetryEvent {
|
|
5
|
+
name: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
userId?: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TelemetryConfig {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
flushInterval?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Telemetry collector for tracking usage
|
|
19
|
+
*/
|
|
20
|
+
export declare class TelemetryCollector {
|
|
21
|
+
private events;
|
|
22
|
+
private enabled;
|
|
23
|
+
private endpoint?;
|
|
24
|
+
private batchSize;
|
|
25
|
+
private flushInterval;
|
|
26
|
+
private flushTimer?;
|
|
27
|
+
private userId?;
|
|
28
|
+
private sessionId;
|
|
29
|
+
constructor(config?: TelemetryConfig);
|
|
30
|
+
private checkEnabled;
|
|
31
|
+
/**
|
|
32
|
+
* Track an event
|
|
33
|
+
*/
|
|
34
|
+
track(name: string, properties?: Record<string, any>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Track feature usage
|
|
37
|
+
*/
|
|
38
|
+
trackFeatureUsage(feature: string, metadata?: Record<string, any>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Track agent execution
|
|
41
|
+
*/
|
|
42
|
+
trackAgentExecution(agentName: string, duration: number, success: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Track tool call
|
|
45
|
+
*/
|
|
46
|
+
trackToolCall(toolName: string, duration: number, success: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* Track LLM call
|
|
49
|
+
*/
|
|
50
|
+
trackLLMCall(provider: string, model: string, tokens: number, duration: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Track error
|
|
53
|
+
*/
|
|
54
|
+
trackError(error: string, context?: Record<string, any>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set user ID
|
|
57
|
+
*/
|
|
58
|
+
setUserId(userId: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Flush events
|
|
61
|
+
*/
|
|
62
|
+
flush(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Enable telemetry
|
|
65
|
+
*/
|
|
66
|
+
enable(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Disable telemetry
|
|
69
|
+
*/
|
|
70
|
+
disable(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if telemetry is enabled
|
|
73
|
+
*/
|
|
74
|
+
isEnabled(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get pending events count
|
|
77
|
+
*/
|
|
78
|
+
getPendingCount(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Cleanup resources
|
|
81
|
+
*/
|
|
82
|
+
cleanup(): void;
|
|
83
|
+
private startFlushTimer;
|
|
84
|
+
private stopFlushTimer;
|
|
85
|
+
private generateSessionId;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get global telemetry instance
|
|
89
|
+
*/
|
|
90
|
+
export declare function getTelemetry(): TelemetryCollector;
|
|
91
|
+
/**
|
|
92
|
+
* Enable telemetry
|
|
93
|
+
*/
|
|
94
|
+
export declare function enableTelemetry(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Disable telemetry
|
|
97
|
+
*/
|
|
98
|
+
export declare function disableTelemetry(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Cleanup telemetry resources
|
|
101
|
+
*/
|
|
102
|
+
export declare function cleanupTelemetry(): void;
|