@agentionai/agents 0.3.0-beta
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/README.md +517 -0
- package/dist/agents/Agent.d.ts +29 -0
- package/dist/agents/Agent.js +28 -0
- package/dist/agents/AgentConfig.d.ts +118 -0
- package/dist/agents/AgentConfig.js +3 -0
- package/dist/agents/AgentEvent.d.ts +18 -0
- package/dist/agents/AgentEvent.js +26 -0
- package/dist/agents/BaseAgent.d.ts +82 -0
- package/dist/agents/BaseAgent.js +121 -0
- package/dist/agents/anthropic/ClaudeAgent.d.ts +46 -0
- package/dist/agents/anthropic/ClaudeAgent.js +262 -0
- package/dist/agents/errors/AgentError.d.ts +47 -0
- package/dist/agents/errors/AgentError.js +74 -0
- package/dist/agents/google/GeminiAgent.d.ts +63 -0
- package/dist/agents/google/GeminiAgent.js +395 -0
- package/dist/agents/mistral/MistralAgent.d.ts +47 -0
- package/dist/agents/mistral/MistralAgent.js +313 -0
- package/dist/agents/model-types.d.ts +30 -0
- package/dist/agents/model-types.js +8 -0
- package/dist/agents/openai/OpenAiAgent.d.ts +48 -0
- package/dist/agents/openai/OpenAiAgent.js +338 -0
- package/dist/chunkers/Chunker.d.ts +53 -0
- package/dist/chunkers/Chunker.js +174 -0
- package/dist/chunkers/RecursiveChunker.d.ts +52 -0
- package/dist/chunkers/RecursiveChunker.js +166 -0
- package/dist/chunkers/TextChunker.d.ts +27 -0
- package/dist/chunkers/TextChunker.js +50 -0
- package/dist/chunkers/TokenChunker.d.ts +60 -0
- package/dist/chunkers/TokenChunker.js +176 -0
- package/dist/chunkers/index.d.ts +6 -0
- package/dist/chunkers/index.js +14 -0
- package/dist/chunkers/types.d.ts +95 -0
- package/dist/chunkers/types.js +3 -0
- package/dist/graph/AgentGraph.d.ts +99 -0
- package/dist/graph/AgentGraph.js +115 -0
- package/dist/graph/BaseExecutor.d.ts +86 -0
- package/dist/graph/BaseExecutor.js +61 -0
- package/dist/graph/GraphMetrics.d.ts +143 -0
- package/dist/graph/GraphMetrics.js +264 -0
- package/dist/graph/MapExecutor.d.ts +39 -0
- package/dist/graph/MapExecutor.js +123 -0
- package/dist/graph/ParallelExecutor.d.ts +51 -0
- package/dist/graph/ParallelExecutor.js +103 -0
- package/dist/graph/Pipeline.d.ts +44 -0
- package/dist/graph/Pipeline.js +109 -0
- package/dist/graph/RouterExecutor.d.ts +89 -0
- package/dist/graph/RouterExecutor.js +209 -0
- package/dist/graph/SequentialExecutor.d.ts +44 -0
- package/dist/graph/SequentialExecutor.js +115 -0
- package/dist/graph/VotingSystem.d.ts +54 -0
- package/dist/graph/VotingSystem.js +106 -0
- package/dist/history/History.d.ts +107 -0
- package/dist/history/History.js +166 -0
- package/dist/history/RedisHistory.d.ts +27 -0
- package/dist/history/RedisHistory.js +55 -0
- package/dist/history/transformers.d.ts +102 -0
- package/dist/history/transformers.js +415 -0
- package/dist/history/types.d.ts +130 -0
- package/dist/history/types.js +55 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +48 -0
- package/dist/ingestion/IngestionPipeline.d.ts +86 -0
- package/dist/ingestion/IngestionPipeline.js +266 -0
- package/dist/ingestion/index.d.ts +3 -0
- package/dist/ingestion/index.js +7 -0
- package/dist/ingestion/types.d.ts +74 -0
- package/dist/ingestion/types.js +3 -0
- package/dist/team/Team.d.ts +46 -0
- package/dist/team/Team.js +104 -0
- package/dist/tools/Tool.d.ts +75 -0
- package/dist/tools/Tool.js +137 -0
- package/dist/vectorstore/Embeddings.d.ts +67 -0
- package/dist/vectorstore/Embeddings.js +54 -0
- package/dist/vectorstore/LanceDBVectorStore.d.ts +149 -0
- package/dist/vectorstore/LanceDBVectorStore.js +338 -0
- package/dist/vectorstore/OpenAIEmbeddings.d.ts +45 -0
- package/dist/vectorstore/OpenAIEmbeddings.js +109 -0
- package/dist/vectorstore/VectorStore.d.ts +255 -0
- package/dist/vectorstore/VectorStore.js +216 -0
- package/dist/vectorstore/index.d.ts +28 -0
- package/dist/vectorstore/index.js +35 -0
- package/dist/viz/VizConfig.d.ts +54 -0
- package/dist/viz/VizConfig.js +100 -0
- package/dist/viz/VizReporter.d.ts +127 -0
- package/dist/viz/VizReporter.js +595 -0
- package/dist/viz/index.d.ts +31 -0
- package/dist/viz/index.js +51 -0
- package/dist/viz/types.d.ts +105 -0
- package/dist/viz/types.js +7 -0
- package/package.json +109 -0
- package/readme.md +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VotingSystem = void 0;
|
|
4
|
+
const BaseExecutor_1 = require("./BaseExecutor");
|
|
5
|
+
const DEFAULT_PROMPT_TEMPLATE = `You are a judge who must select the best answer from multiple experts.
|
|
6
|
+
|
|
7
|
+
Original question: {originalQuestion}
|
|
8
|
+
|
|
9
|
+
Expert answers:
|
|
10
|
+
{expertAnswers}
|
|
11
|
+
|
|
12
|
+
Select the best answer, or synthesize a better answer from the experts' inputs.
|
|
13
|
+
Your response should be the final answer without explanation or preamble.`;
|
|
14
|
+
/**
|
|
15
|
+
* A voting system that uses a judge agent to select or synthesize
|
|
16
|
+
* the best answer from multiple solutions.
|
|
17
|
+
*
|
|
18
|
+
* Typically used after a ParallelExecutor to evaluate multiple expert opinions.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const voting = new VotingSystem(judgeAgent);
|
|
23
|
+
* const result = await voting.execute({
|
|
24
|
+
* originalInput: "What is the best approach?",
|
|
25
|
+
* solutions: [expertA_answer, expertB_answer, expertC_answer]
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
class VotingSystem extends BaseExecutor_1.BaseExecutor {
|
|
30
|
+
constructor(judge, options = {}) {
|
|
31
|
+
super();
|
|
32
|
+
this.name = "VotingSystem";
|
|
33
|
+
this.nodeType = "voting";
|
|
34
|
+
this.judge = judge;
|
|
35
|
+
this.promptTemplate = options.promptTemplate || DEFAULT_PROMPT_TEMPLATE;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates the solutions and returns the judge's verdict.
|
|
39
|
+
* @param input - Object containing originalInput and solutions array
|
|
40
|
+
* @returns The judge's selected or synthesized answer
|
|
41
|
+
* @throws Error if input is a string (must be VotingInput object)
|
|
42
|
+
*/
|
|
43
|
+
async execute(input) {
|
|
44
|
+
const collector = this.getCollector();
|
|
45
|
+
const execId = collector?.startExecution(this.name, "voting", input);
|
|
46
|
+
if (typeof input === "string") {
|
|
47
|
+
const error = new Error("VotingSystem requires an object with originalInput and solutions properties. " +
|
|
48
|
+
"Use as part of a pipeline after a parallel executor, or provide a VotingInput object.");
|
|
49
|
+
if (execId)
|
|
50
|
+
collector?.endExecution(execId, false, undefined, undefined, error.message);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
const { originalInput, solutions } = input;
|
|
54
|
+
if (!solutions || solutions.length === 0) {
|
|
55
|
+
const error = new Error("VotingSystem requires at least one solution to evaluate");
|
|
56
|
+
if (execId)
|
|
57
|
+
collector?.endExecution(execId, false, undefined, undefined, error.message);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
const formattedAnswers = solutions
|
|
61
|
+
.map((solution, index) => `Expert ${index + 1}: ${solution}`)
|
|
62
|
+
.join("\n\n");
|
|
63
|
+
const votingPrompt = this.promptTemplate
|
|
64
|
+
.replace("{originalQuestion}", originalInput || "")
|
|
65
|
+
.replace("{expertAnswers}", formattedAnswers);
|
|
66
|
+
// Track judge execution
|
|
67
|
+
const judgeName = this.judge.getName?.() ?? "Judge";
|
|
68
|
+
const judgeExecId = collector?.startExecution(judgeName, "agent", votingPrompt);
|
|
69
|
+
try {
|
|
70
|
+
const result = (await this.judge.execute(votingPrompt));
|
|
71
|
+
// Extract token usage from judge
|
|
72
|
+
const tokenUsage = this.extractTokenUsage(this.judge);
|
|
73
|
+
if (judgeExecId)
|
|
74
|
+
collector?.endExecution(judgeExecId, true, result, tokenUsage);
|
|
75
|
+
if (execId)
|
|
76
|
+
collector?.endExecution(execId, true, result, tokenUsage);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (judgeExecId) {
|
|
81
|
+
collector?.endExecution(judgeExecId, false, undefined, undefined, error instanceof Error ? error.message : String(error));
|
|
82
|
+
}
|
|
83
|
+
if (execId) {
|
|
84
|
+
collector?.endExecution(execId, false, undefined, undefined, error instanceof Error ? error.message : String(error));
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Attempt to extract token usage from an agent.
|
|
91
|
+
* Converts from agent's snake_case format to metrics camelCase format.
|
|
92
|
+
*/
|
|
93
|
+
extractTokenUsage(agent) {
|
|
94
|
+
const agentWithUsage = agent;
|
|
95
|
+
if (!agentWithUsage.lastTokenUsage)
|
|
96
|
+
return undefined;
|
|
97
|
+
// Convert from snake_case to camelCase
|
|
98
|
+
return {
|
|
99
|
+
inputTokens: agentWithUsage.lastTokenUsage.input_tokens,
|
|
100
|
+
outputTokens: agentWithUsage.lastTokenUsage.output_tokens,
|
|
101
|
+
totalTokens: agentWithUsage.lastTokenUsage.total_tokens,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.VotingSystem = VotingSystem;
|
|
106
|
+
//# sourceMappingURL=VotingSystem.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { HistoryEntry, MessageRole, MessageContent } from "./types";
|
|
3
|
+
export type { HistoryEntry, MessageRole, MessageContent } from "./types";
|
|
4
|
+
export { text, toolUse, toolResult, textMessage, isTextContent, isToolUseContent, isToolResultContent, } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Internal entry with metadata
|
|
7
|
+
*/
|
|
8
|
+
type EntryWithMetadata = HistoryEntry & {
|
|
9
|
+
__metadata: {
|
|
10
|
+
date: string;
|
|
11
|
+
contentLength: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* History configuration options
|
|
16
|
+
*/
|
|
17
|
+
type HistoryOptions = {
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
transient?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Manages conversation history in a provider-agnostic format.
|
|
23
|
+
*
|
|
24
|
+
* This class stores history entries in a normalized format that can be
|
|
25
|
+
* transformed to any LLM provider's native format using the transformers.
|
|
26
|
+
*
|
|
27
|
+
* History can be shared between agents of different providers, enabling
|
|
28
|
+
* cross-provider conversations and handoffs.
|
|
29
|
+
*
|
|
30
|
+
* @example Basic usage
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const history = new History();
|
|
33
|
+
* history.addText("user", "Hello!");
|
|
34
|
+
* history.addText("assistant", "Hi there!");
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Sharing between agents
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const history = new History();
|
|
40
|
+
* const claudeAgent = new ClaudeAgent({ ... }, history);
|
|
41
|
+
* const openAiAgent = new OpenAiAgent({ ... }, history);
|
|
42
|
+
* // Both agents share the same conversation history
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class History extends EventEmitter {
|
|
46
|
+
protected _entries: EntryWithMetadata[];
|
|
47
|
+
private options;
|
|
48
|
+
transient: boolean;
|
|
49
|
+
constructor(entries?: HistoryEntry[], options?: HistoryOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Add a complete history entry
|
|
52
|
+
*/
|
|
53
|
+
addEntry(entry: HistoryEntry): void;
|
|
54
|
+
/**
|
|
55
|
+
* Add a simple text message
|
|
56
|
+
*/
|
|
57
|
+
addText(role: MessageRole, content: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Add a message with multiple content blocks
|
|
60
|
+
*/
|
|
61
|
+
addMessage(role: MessageRole, content: MessageContent[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* Add a system message
|
|
64
|
+
*/
|
|
65
|
+
addSystem(content: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get all entries (without internal metadata)
|
|
68
|
+
*/
|
|
69
|
+
get entries(): HistoryEntry[];
|
|
70
|
+
/**
|
|
71
|
+
* Get the number of entries
|
|
72
|
+
*/
|
|
73
|
+
get length(): number;
|
|
74
|
+
/**
|
|
75
|
+
* Get total content size in characters
|
|
76
|
+
*/
|
|
77
|
+
get size(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Get the last entry
|
|
80
|
+
*/
|
|
81
|
+
lastEntry(): HistoryEntry | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Get system message if present
|
|
84
|
+
*/
|
|
85
|
+
getSystemMessage(): string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Get entries without system messages
|
|
88
|
+
*/
|
|
89
|
+
getMessagesWithoutSystem(): HistoryEntry[];
|
|
90
|
+
/**
|
|
91
|
+
* Clear all history entries
|
|
92
|
+
*/
|
|
93
|
+
clear(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Serialize history to JSON
|
|
96
|
+
*/
|
|
97
|
+
toJSON(): string;
|
|
98
|
+
/**
|
|
99
|
+
* Create a History instance from JSON
|
|
100
|
+
*/
|
|
101
|
+
static fromJSON(json: string, options?: HistoryOptions): History;
|
|
102
|
+
/**
|
|
103
|
+
* Create a copy of this history
|
|
104
|
+
*/
|
|
105
|
+
clone(options?: HistoryOptions): History;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=History.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.History = exports.isToolResultContent = exports.isToolUseContent = exports.isTextContent = exports.textMessage = exports.toolResult = exports.toolUse = exports.text = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
var types_2 = require("./types");
|
|
10
|
+
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return types_2.text; } });
|
|
11
|
+
Object.defineProperty(exports, "toolUse", { enumerable: true, get: function () { return types_2.toolUse; } });
|
|
12
|
+
Object.defineProperty(exports, "toolResult", { enumerable: true, get: function () { return types_2.toolResult; } });
|
|
13
|
+
Object.defineProperty(exports, "textMessage", { enumerable: true, get: function () { return types_2.textMessage; } });
|
|
14
|
+
Object.defineProperty(exports, "isTextContent", { enumerable: true, get: function () { return types_2.isTextContent; } });
|
|
15
|
+
Object.defineProperty(exports, "isToolUseContent", { enumerable: true, get: function () { return types_2.isToolUseContent; } });
|
|
16
|
+
Object.defineProperty(exports, "isToolResultContent", { enumerable: true, get: function () { return types_2.isToolResultContent; } });
|
|
17
|
+
/**
|
|
18
|
+
* Manages conversation history in a provider-agnostic format.
|
|
19
|
+
*
|
|
20
|
+
* This class stores history entries in a normalized format that can be
|
|
21
|
+
* transformed to any LLM provider's native format using the transformers.
|
|
22
|
+
*
|
|
23
|
+
* History can be shared between agents of different providers, enabling
|
|
24
|
+
* cross-provider conversations and handoffs.
|
|
25
|
+
*
|
|
26
|
+
* @example Basic usage
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const history = new History();
|
|
29
|
+
* history.addText("user", "Hello!");
|
|
30
|
+
* history.addText("assistant", "Hi there!");
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Sharing between agents
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const history = new History();
|
|
36
|
+
* const claudeAgent = new ClaudeAgent({ ... }, history);
|
|
37
|
+
* const openAiAgent = new OpenAiAgent({ ... }, history);
|
|
38
|
+
* // Both agents share the same conversation history
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class History extends events_1.default {
|
|
42
|
+
constructor(entries = [], options = {}) {
|
|
43
|
+
super();
|
|
44
|
+
this._entries = [];
|
|
45
|
+
this.transient = false;
|
|
46
|
+
this.options = options;
|
|
47
|
+
this.transient = Boolean(options?.transient);
|
|
48
|
+
// Convert initial entries to internal format with metadata
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
this.addEntry(entry);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Add a complete history entry
|
|
55
|
+
*/
|
|
56
|
+
addEntry(entry) {
|
|
57
|
+
const __metadata = {
|
|
58
|
+
date: new Date().toISOString(),
|
|
59
|
+
contentLength: JSON.stringify(entry.content).length,
|
|
60
|
+
};
|
|
61
|
+
this._entries.push({
|
|
62
|
+
...entry,
|
|
63
|
+
__metadata,
|
|
64
|
+
});
|
|
65
|
+
this.emit("entry", entry);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Add a simple text message
|
|
69
|
+
*/
|
|
70
|
+
addText(role, content) {
|
|
71
|
+
this.addEntry({
|
|
72
|
+
role,
|
|
73
|
+
content: [(0, types_1.text)(content)],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add a message with multiple content blocks
|
|
78
|
+
*/
|
|
79
|
+
addMessage(role, content) {
|
|
80
|
+
this.addEntry({ role, content });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Add a system message
|
|
84
|
+
*/
|
|
85
|
+
addSystem(content) {
|
|
86
|
+
this.addText("system", content);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get all entries (without internal metadata)
|
|
90
|
+
*/
|
|
91
|
+
get entries() {
|
|
92
|
+
return this._entries.map((entry) => {
|
|
93
|
+
const { __metadata, ...rest } = entry;
|
|
94
|
+
return rest;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the number of entries
|
|
99
|
+
*/
|
|
100
|
+
get length() {
|
|
101
|
+
return this._entries.length;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get total content size in characters
|
|
105
|
+
*/
|
|
106
|
+
get size() {
|
|
107
|
+
return this._entries.reduce((total, { __metadata }) => {
|
|
108
|
+
return total + __metadata.contentLength;
|
|
109
|
+
}, 0);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the last entry
|
|
113
|
+
*/
|
|
114
|
+
lastEntry() {
|
|
115
|
+
if (this._entries.length === 0)
|
|
116
|
+
return undefined;
|
|
117
|
+
const { __metadata, ...entry } = this._entries[this._entries.length - 1];
|
|
118
|
+
return entry;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get system message if present
|
|
122
|
+
*/
|
|
123
|
+
getSystemMessage() {
|
|
124
|
+
const systemEntry = this._entries.find((e) => e.role === "system");
|
|
125
|
+
if (!systemEntry)
|
|
126
|
+
return undefined;
|
|
127
|
+
return systemEntry.content
|
|
128
|
+
.filter(types_1.isTextContent)
|
|
129
|
+
.map((c) => c.text)
|
|
130
|
+
.join("\n");
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get entries without system messages
|
|
134
|
+
*/
|
|
135
|
+
getMessagesWithoutSystem() {
|
|
136
|
+
return this.entries.filter((e) => e.role !== "system");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Clear all history entries
|
|
140
|
+
*/
|
|
141
|
+
clear() {
|
|
142
|
+
this._entries = [];
|
|
143
|
+
this.emit("clear");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Serialize history to JSON
|
|
147
|
+
*/
|
|
148
|
+
toJSON() {
|
|
149
|
+
return JSON.stringify(this.entries);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a History instance from JSON
|
|
153
|
+
*/
|
|
154
|
+
static fromJSON(json, options) {
|
|
155
|
+
const entries = JSON.parse(json);
|
|
156
|
+
return new History(entries, options);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create a copy of this history
|
|
160
|
+
*/
|
|
161
|
+
clone(options) {
|
|
162
|
+
return new History(this.entries, options ?? this.options);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.History = History;
|
|
166
|
+
//# sourceMappingURL=History.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { History } from "./History";
|
|
2
|
+
interface RedisInstance {
|
|
3
|
+
get(key: string): Promise<string | null>;
|
|
4
|
+
set(key: string, content: string): Promise<"OK">;
|
|
5
|
+
}
|
|
6
|
+
export declare class RedisHistory extends History {
|
|
7
|
+
private redisInstance;
|
|
8
|
+
constructor(redisInstance: RedisInstance);
|
|
9
|
+
/**
|
|
10
|
+
* Loads history entries from Redis using the specified key
|
|
11
|
+
*
|
|
12
|
+
* @param {string} key - The Redis key to retrieve history entries from
|
|
13
|
+
* @returns {Promise<void>} A promise that resolves when history is loaded
|
|
14
|
+
* @throws {Error} If there's an issue retrieving or parsing the history entries
|
|
15
|
+
*/
|
|
16
|
+
load(key: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Saves the current history entries to Redis using the specified key
|
|
19
|
+
*
|
|
20
|
+
* @param {string} key - The Redis key to save history entries under
|
|
21
|
+
* @returns {Promise<void>} A promise that resolves when history is saved
|
|
22
|
+
* @throws {Error} If there's an issue serializing or saving the history entries
|
|
23
|
+
*/
|
|
24
|
+
save(key: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=RedisHistory.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisHistory = void 0;
|
|
4
|
+
const History_1 = require("./History");
|
|
5
|
+
class RedisHistory extends History_1.History {
|
|
6
|
+
constructor(redisInstance) {
|
|
7
|
+
super([], { transient: false });
|
|
8
|
+
this.redisInstance = redisInstance;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Loads history entries from Redis using the specified key
|
|
12
|
+
*
|
|
13
|
+
* @param {string} key - The Redis key to retrieve history entries from
|
|
14
|
+
* @returns {Promise<void>} A promise that resolves when history is loaded
|
|
15
|
+
* @throws {Error} If there's an issue retrieving or parsing the history entries
|
|
16
|
+
*/
|
|
17
|
+
async load(key) {
|
|
18
|
+
try {
|
|
19
|
+
// Retrieve the serialized history from Redis
|
|
20
|
+
const serializedHistory = await this.redisInstance.get(key);
|
|
21
|
+
// If no history exists for the key, return early
|
|
22
|
+
if (!serializedHistory) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Parse the serialized history and create a new History instance
|
|
26
|
+
const entries = JSON.parse(serializedHistory);
|
|
27
|
+
this._entries = entries;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(`Error loading history from Redis key "${key}":`, error);
|
|
31
|
+
throw new Error(`Failed to load history: ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Saves the current history entries to Redis using the specified key
|
|
36
|
+
*
|
|
37
|
+
* @param {string} key - The Redis key to save history entries under
|
|
38
|
+
* @returns {Promise<void>} A promise that resolves when history is saved
|
|
39
|
+
* @throws {Error} If there's an issue serializing or saving the history entries
|
|
40
|
+
*/
|
|
41
|
+
async save(key) {
|
|
42
|
+
try {
|
|
43
|
+
// Serialize the current history entries
|
|
44
|
+
const serializedHistory = this.toJSON();
|
|
45
|
+
// Save the serialized history to Redis
|
|
46
|
+
await this.redisInstance.set(key, serializedHistory);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error(`Error saving history to Redis key "${key}":`, error);
|
|
50
|
+
throw new Error(`Failed to save history: ${error instanceof Error ? error.message : String(error)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.RedisHistory = RedisHistory;
|
|
55
|
+
//# sourceMappingURL=RedisHistory.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Transformers
|
|
3
|
+
*
|
|
4
|
+
* Transform between normalized HistoryEntry format and provider-specific formats.
|
|
5
|
+
*/
|
|
6
|
+
import type { MessageParam, ContentBlock } from "@anthropic-ai/sdk/resources";
|
|
7
|
+
import type { ResponseInputItem } from "openai/resources/responses/responses";
|
|
8
|
+
import type { Content, Part } from "@google/generative-ai";
|
|
9
|
+
import { HistoryEntry } from "./types";
|
|
10
|
+
export declare const anthropicTransformer: {
|
|
11
|
+
/**
|
|
12
|
+
* Convert normalized entries to Anthropic MessageParam format
|
|
13
|
+
*/
|
|
14
|
+
toProvider(entries: HistoryEntry[]): MessageParam[];
|
|
15
|
+
/**
|
|
16
|
+
* Convert Anthropic response content to normalized HistoryEntry
|
|
17
|
+
*/
|
|
18
|
+
fromProviderContent(role: "user" | "assistant", content: ContentBlock[]): HistoryEntry;
|
|
19
|
+
/**
|
|
20
|
+
* Extract system message from entries
|
|
21
|
+
*/
|
|
22
|
+
getSystemMessage(entries: HistoryEntry[]): string | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare const openAiTransformer: {
|
|
25
|
+
/**
|
|
26
|
+
* Convert normalized entries to OpenAI ResponseInputItem format
|
|
27
|
+
*/
|
|
28
|
+
toProvider(entries: HistoryEntry[]): ResponseInputItem[];
|
|
29
|
+
/**
|
|
30
|
+
* Convert OpenAI response to normalized HistoryEntry
|
|
31
|
+
*/
|
|
32
|
+
fromProviderMessage(role: "assistant" | "user", outputText: string, functionCalls?: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
call_id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
arguments: string;
|
|
37
|
+
}>): HistoryEntry;
|
|
38
|
+
/**
|
|
39
|
+
* Create a tool result entry from OpenAI function call output
|
|
40
|
+
*/
|
|
41
|
+
toolResultEntry(call_id: string, output: string, is_error?: boolean): HistoryEntry;
|
|
42
|
+
};
|
|
43
|
+
type MistralMessage = {
|
|
44
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
45
|
+
content: string;
|
|
46
|
+
toolCalls?: Array<{
|
|
47
|
+
id: string;
|
|
48
|
+
function: {
|
|
49
|
+
name: string;
|
|
50
|
+
arguments: string;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
name?: string;
|
|
54
|
+
toolCallId?: string;
|
|
55
|
+
};
|
|
56
|
+
type MistralResponseMessage = {
|
|
57
|
+
content?: string | null | Array<{
|
|
58
|
+
type: string;
|
|
59
|
+
text?: string;
|
|
60
|
+
} | string>;
|
|
61
|
+
toolCalls?: Array<{
|
|
62
|
+
id?: string;
|
|
63
|
+
function: {
|
|
64
|
+
name: string;
|
|
65
|
+
arguments: unknown;
|
|
66
|
+
};
|
|
67
|
+
}> | null;
|
|
68
|
+
};
|
|
69
|
+
export declare const mistralTransformer: {
|
|
70
|
+
/**
|
|
71
|
+
* Convert normalized entries to Mistral message format
|
|
72
|
+
*/
|
|
73
|
+
toProvider(entries: HistoryEntry[]): MistralMessage[];
|
|
74
|
+
/**
|
|
75
|
+
* Convert Mistral response to normalized HistoryEntry
|
|
76
|
+
*/
|
|
77
|
+
fromProviderMessage(message: MistralResponseMessage): HistoryEntry;
|
|
78
|
+
/**
|
|
79
|
+
* Create a tool result entry for Mistral
|
|
80
|
+
*/
|
|
81
|
+
toolResultEntry(tool_call_id: string, name: string, output: string): HistoryEntry;
|
|
82
|
+
};
|
|
83
|
+
export declare const geminiTransformer: {
|
|
84
|
+
/**
|
|
85
|
+
* Convert normalized entries to Gemini Content format
|
|
86
|
+
*/
|
|
87
|
+
toProvider(entries: HistoryEntry[]): Content[];
|
|
88
|
+
/**
|
|
89
|
+
* Convert Gemini response parts to normalized HistoryEntry
|
|
90
|
+
*/
|
|
91
|
+
fromProviderContent(role: "user" | "assistant", parts: Part[]): HistoryEntry;
|
|
92
|
+
/**
|
|
93
|
+
* Create a tool result entry for Gemini
|
|
94
|
+
*/
|
|
95
|
+
toolResultEntry(functionName: string, output: string, is_error?: boolean): HistoryEntry;
|
|
96
|
+
/**
|
|
97
|
+
* Extract system message from entries
|
|
98
|
+
*/
|
|
99
|
+
getSystemMessage(entries: HistoryEntry[]): string | undefined;
|
|
100
|
+
};
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=transformers.d.ts.map
|