@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,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provider Transformers
|
|
4
|
+
*
|
|
5
|
+
* Transform between normalized HistoryEntry format and provider-specific formats.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = void 0;
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Anthropic Transformer
|
|
12
|
+
// =============================================================================
|
|
13
|
+
exports.anthropicTransformer = {
|
|
14
|
+
/**
|
|
15
|
+
* Convert normalized entries to Anthropic MessageParam format
|
|
16
|
+
*/
|
|
17
|
+
toProvider(entries) {
|
|
18
|
+
return entries
|
|
19
|
+
.filter((entry) => entry.role !== "system") // Anthropic handles system separately
|
|
20
|
+
.map((entry) => {
|
|
21
|
+
const role = entry.role === "assistant" ? "assistant" : "user";
|
|
22
|
+
// Convert content blocks to Anthropic's ContentBlockParam
|
|
23
|
+
const content = entry.content.map((block) => {
|
|
24
|
+
if ((0, types_1.isTextContent)(block)) {
|
|
25
|
+
return { type: "text", text: block.text };
|
|
26
|
+
}
|
|
27
|
+
if ((0, types_1.isToolUseContent)(block)) {
|
|
28
|
+
return {
|
|
29
|
+
type: "tool_use",
|
|
30
|
+
id: block.id,
|
|
31
|
+
name: block.name,
|
|
32
|
+
input: block.input,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if ((0, types_1.isToolResultContent)(block)) {
|
|
36
|
+
return {
|
|
37
|
+
type: "tool_result",
|
|
38
|
+
tool_use_id: block.tool_use_id,
|
|
39
|
+
content: block.content,
|
|
40
|
+
is_error: block.is_error,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Unknown content type: ${block.type}`);
|
|
44
|
+
});
|
|
45
|
+
return { role, content };
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Convert Anthropic response content to normalized HistoryEntry
|
|
50
|
+
*/
|
|
51
|
+
fromProviderContent(role, content) {
|
|
52
|
+
const normalizedContent = content.map((block) => {
|
|
53
|
+
if (block.type === "text") {
|
|
54
|
+
return (0, types_1.text)(block.text);
|
|
55
|
+
}
|
|
56
|
+
if (block.type === "tool_use") {
|
|
57
|
+
return (0, types_1.toolUse)(block.id, block.name, block.input);
|
|
58
|
+
}
|
|
59
|
+
// Handle thinking blocks or other types as text
|
|
60
|
+
return (0, types_1.text)(JSON.stringify(block));
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
role,
|
|
64
|
+
content: normalizedContent,
|
|
65
|
+
meta: { provider: "anthropic" },
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Extract system message from entries
|
|
70
|
+
*/
|
|
71
|
+
getSystemMessage(entries) {
|
|
72
|
+
const systemEntry = entries.find((e) => e.role === "system");
|
|
73
|
+
if (!systemEntry)
|
|
74
|
+
return undefined;
|
|
75
|
+
return systemEntry.content
|
|
76
|
+
.filter(types_1.isTextContent)
|
|
77
|
+
.map((c) => c.text)
|
|
78
|
+
.join("\n");
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
// =============================================================================
|
|
82
|
+
// OpenAI Transformer
|
|
83
|
+
// =============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Map to track ID conversions from other providers to OpenAI format.
|
|
86
|
+
* OpenAI requires IDs to start with 'fc_' for function calls.
|
|
87
|
+
*/
|
|
88
|
+
const idMappingToOpenAi = new Map();
|
|
89
|
+
/**
|
|
90
|
+
* Convert a tool call ID to OpenAI format.
|
|
91
|
+
* OpenAI expects IDs starting with 'fc_'.
|
|
92
|
+
*/
|
|
93
|
+
function toOpenAiId(originalId) {
|
|
94
|
+
// Already an OpenAI ID
|
|
95
|
+
if (originalId.startsWith("fc_")) {
|
|
96
|
+
return originalId;
|
|
97
|
+
}
|
|
98
|
+
// Check if we've already mapped this ID
|
|
99
|
+
if (idMappingToOpenAi.has(originalId)) {
|
|
100
|
+
return idMappingToOpenAi.get(originalId);
|
|
101
|
+
}
|
|
102
|
+
// Generate a new OpenAI-compatible ID and store the mapping
|
|
103
|
+
const newId = `fc_${originalId.replace(/[^a-zA-Z0-9]/g, "").slice(0, 24)}`;
|
|
104
|
+
idMappingToOpenAi.set(originalId, newId);
|
|
105
|
+
return newId;
|
|
106
|
+
}
|
|
107
|
+
exports.openAiTransformer = {
|
|
108
|
+
/**
|
|
109
|
+
* Convert normalized entries to OpenAI ResponseInputItem format
|
|
110
|
+
*/
|
|
111
|
+
toProvider(entries) {
|
|
112
|
+
const items = [];
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
if (entry.role === "system") {
|
|
115
|
+
items.push({
|
|
116
|
+
type: "message",
|
|
117
|
+
role: "system",
|
|
118
|
+
content: entry.content
|
|
119
|
+
.filter(types_1.isTextContent)
|
|
120
|
+
.map((c) => c.text)
|
|
121
|
+
.join("\n"),
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Separate tool_use from other content for OpenAI format
|
|
126
|
+
const textBlocks = entry.content.filter(types_1.isTextContent);
|
|
127
|
+
const toolUseBlocks = entry.content.filter(types_1.isToolUseContent);
|
|
128
|
+
const toolResultBlocks = entry.content.filter(types_1.isToolResultContent);
|
|
129
|
+
// Add text message if present
|
|
130
|
+
if (textBlocks.length > 0 && entry.role !== "user") {
|
|
131
|
+
items.push({
|
|
132
|
+
type: "message",
|
|
133
|
+
role: entry.role,
|
|
134
|
+
content: textBlocks.map((c) => c.text).join("\n"),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else if (entry.role === "user" &&
|
|
138
|
+
textBlocks.length > 0 &&
|
|
139
|
+
toolResultBlocks.length === 0) {
|
|
140
|
+
items.push({
|
|
141
|
+
type: "message",
|
|
142
|
+
role: "user",
|
|
143
|
+
content: textBlocks.map((c) => c.text).join("\n"),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// Add tool calls as separate function_call items (OpenAI format)
|
|
147
|
+
// Convert IDs to OpenAI format if they came from another provider
|
|
148
|
+
for (const toolBlock of toolUseBlocks) {
|
|
149
|
+
const openAiId = toOpenAiId(toolBlock.id);
|
|
150
|
+
items.push({
|
|
151
|
+
type: "function_call",
|
|
152
|
+
id: openAiId,
|
|
153
|
+
call_id: openAiId,
|
|
154
|
+
name: toolBlock.name,
|
|
155
|
+
arguments: JSON.stringify(toolBlock.input),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Add tool results as function_call_output items
|
|
159
|
+
// Use the same ID mapping to match results with their calls
|
|
160
|
+
for (const resultBlock of toolResultBlocks) {
|
|
161
|
+
const openAiId = toOpenAiId(resultBlock.tool_use_id);
|
|
162
|
+
items.push({
|
|
163
|
+
type: "function_call_output",
|
|
164
|
+
call_id: openAiId,
|
|
165
|
+
output: resultBlock.content,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return items;
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* Convert OpenAI response to normalized HistoryEntry
|
|
173
|
+
*/
|
|
174
|
+
fromProviderMessage(role, outputText, functionCalls) {
|
|
175
|
+
const content = [];
|
|
176
|
+
if (outputText) {
|
|
177
|
+
content.push((0, types_1.text)(outputText));
|
|
178
|
+
}
|
|
179
|
+
if (functionCalls) {
|
|
180
|
+
for (const call of functionCalls) {
|
|
181
|
+
let input = {};
|
|
182
|
+
try {
|
|
183
|
+
input = JSON.parse(call.arguments);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
input = { raw: call.arguments };
|
|
187
|
+
}
|
|
188
|
+
content.push((0, types_1.toolUse)(call.call_id, call.name, input));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
role,
|
|
193
|
+
content,
|
|
194
|
+
meta: { provider: "openai" },
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
/**
|
|
198
|
+
* Create a tool result entry from OpenAI function call output
|
|
199
|
+
*/
|
|
200
|
+
toolResultEntry(call_id, output, is_error) {
|
|
201
|
+
return {
|
|
202
|
+
role: "user",
|
|
203
|
+
content: [(0, types_1.toolResult)(call_id, output, is_error)],
|
|
204
|
+
meta: { provider: "openai", call_id },
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
exports.mistralTransformer = {
|
|
209
|
+
/**
|
|
210
|
+
* Convert normalized entries to Mistral message format
|
|
211
|
+
*/
|
|
212
|
+
toProvider(entries) {
|
|
213
|
+
const messages = [];
|
|
214
|
+
for (const entry of entries) {
|
|
215
|
+
const textBlocks = entry.content.filter(types_1.isTextContent);
|
|
216
|
+
const toolUseBlocks = entry.content.filter(types_1.isToolUseContent);
|
|
217
|
+
const toolResultBlocks = entry.content.filter(types_1.isToolResultContent);
|
|
218
|
+
if (entry.role === "system") {
|
|
219
|
+
messages.push({
|
|
220
|
+
role: "system",
|
|
221
|
+
content: textBlocks.map((c) => c.text).join("\n"),
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (entry.role === "assistant") {
|
|
226
|
+
const contentText = textBlocks.map((c) => c.text).join("\n");
|
|
227
|
+
// When there are tool calls but no text content, content should be null or empty string
|
|
228
|
+
// Some APIs are picky about this
|
|
229
|
+
const content = contentText || (toolUseBlocks.length > 0 ? null : "");
|
|
230
|
+
const msg = {
|
|
231
|
+
role: "assistant",
|
|
232
|
+
content: content,
|
|
233
|
+
};
|
|
234
|
+
if (toolUseBlocks.length > 0) {
|
|
235
|
+
msg.toolCalls = toolUseBlocks.map((block) => ({
|
|
236
|
+
id: block.id,
|
|
237
|
+
function: {
|
|
238
|
+
name: block.name,
|
|
239
|
+
arguments: JSON.stringify(block.input),
|
|
240
|
+
},
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
messages.push(msg);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// User role - could be text or tool results
|
|
247
|
+
if (toolResultBlocks.length > 0) {
|
|
248
|
+
// Mistral uses separate "tool" role messages for each result
|
|
249
|
+
// We need to find the corresponding tool name from the assistant's tool_calls
|
|
250
|
+
for (const result of toolResultBlocks) {
|
|
251
|
+
// Find the tool name from meta if available
|
|
252
|
+
const toolName = entry.meta?.tool_name || "";
|
|
253
|
+
messages.push({
|
|
254
|
+
role: "tool",
|
|
255
|
+
content: result.content,
|
|
256
|
+
toolCallId: result.tool_use_id,
|
|
257
|
+
name: toolName,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (textBlocks.length > 0) {
|
|
262
|
+
messages.push({
|
|
263
|
+
role: "user",
|
|
264
|
+
content: textBlocks.map((c) => c.text).join("\n"),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return messages;
|
|
269
|
+
},
|
|
270
|
+
/**
|
|
271
|
+
* Convert Mistral response to normalized HistoryEntry
|
|
272
|
+
*/
|
|
273
|
+
fromProviderMessage(message) {
|
|
274
|
+
const content = [];
|
|
275
|
+
// Handle content
|
|
276
|
+
if (typeof message.content === "string" && message.content) {
|
|
277
|
+
content.push((0, types_1.text)(message.content));
|
|
278
|
+
}
|
|
279
|
+
else if (Array.isArray(message.content)) {
|
|
280
|
+
for (const chunk of message.content) {
|
|
281
|
+
if (typeof chunk === "string") {
|
|
282
|
+
content.push((0, types_1.text)(chunk));
|
|
283
|
+
}
|
|
284
|
+
else if (chunk.type === "text" && chunk.text) {
|
|
285
|
+
content.push((0, types_1.text)(chunk.text));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// Handle tool calls
|
|
290
|
+
if (message.toolCalls) {
|
|
291
|
+
for (const call of message.toolCalls) {
|
|
292
|
+
const args = typeof call.function.arguments === "string"
|
|
293
|
+
? JSON.parse(call.function.arguments)
|
|
294
|
+
: call.function.arguments;
|
|
295
|
+
content.push((0, types_1.toolUse)(call.id || "", call.function.name, args));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
role: "assistant",
|
|
300
|
+
content,
|
|
301
|
+
meta: { provider: "mistral" },
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
/**
|
|
305
|
+
* Create a tool result entry for Mistral
|
|
306
|
+
*/
|
|
307
|
+
toolResultEntry(tool_call_id, name, output) {
|
|
308
|
+
return {
|
|
309
|
+
role: "user",
|
|
310
|
+
content: [(0, types_1.toolResult)(tool_call_id, output)],
|
|
311
|
+
meta: { provider: "mistral", tool_call_id, tool_name: name },
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
// =============================================================================
|
|
316
|
+
// Gemini Transformer
|
|
317
|
+
// =============================================================================
|
|
318
|
+
exports.geminiTransformer = {
|
|
319
|
+
/**
|
|
320
|
+
* Convert normalized entries to Gemini Content format
|
|
321
|
+
*/
|
|
322
|
+
toProvider(entries) {
|
|
323
|
+
const contents = [];
|
|
324
|
+
for (const entry of entries) {
|
|
325
|
+
// Skip system messages - Gemini handles these separately via systemInstruction
|
|
326
|
+
if (entry.role === "system") {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const textBlocks = entry.content.filter(types_1.isTextContent);
|
|
330
|
+
const toolUseBlocks = entry.content.filter(types_1.isToolUseContent);
|
|
331
|
+
const toolResultBlocks = entry.content.filter(types_1.isToolResultContent);
|
|
332
|
+
// Gemini uses "user" and "model" roles
|
|
333
|
+
const role = entry.role === "assistant" ? "model" : "user";
|
|
334
|
+
const parts = [];
|
|
335
|
+
// Add text parts
|
|
336
|
+
for (const block of textBlocks) {
|
|
337
|
+
parts.push({ text: block.text });
|
|
338
|
+
}
|
|
339
|
+
// Add function call parts (for assistant/model messages)
|
|
340
|
+
for (const block of toolUseBlocks) {
|
|
341
|
+
parts.push({
|
|
342
|
+
functionCall: {
|
|
343
|
+
name: block.name,
|
|
344
|
+
args: block.input,
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
// Add function response parts (for user messages with tool results)
|
|
349
|
+
for (const block of toolResultBlocks) {
|
|
350
|
+
// Parse content if it's JSON, otherwise wrap in response object
|
|
351
|
+
let responseData;
|
|
352
|
+
try {
|
|
353
|
+
responseData = JSON.parse(block.content);
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
responseData = { result: block.content };
|
|
357
|
+
}
|
|
358
|
+
parts.push({
|
|
359
|
+
functionResponse: {
|
|
360
|
+
name: block.tool_use_id, // Gemini uses the function name, but we store tool_use_id
|
|
361
|
+
response: responseData,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
if (parts.length > 0) {
|
|
366
|
+
contents.push({ role, parts });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return contents;
|
|
370
|
+
},
|
|
371
|
+
/**
|
|
372
|
+
* Convert Gemini response parts to normalized HistoryEntry
|
|
373
|
+
*/
|
|
374
|
+
fromProviderContent(role, parts) {
|
|
375
|
+
const normalizedContent = [];
|
|
376
|
+
for (const part of parts) {
|
|
377
|
+
if ("text" in part && part.text) {
|
|
378
|
+
normalizedContent.push((0, types_1.text)(part.text));
|
|
379
|
+
}
|
|
380
|
+
if ("functionCall" in part && part.functionCall) {
|
|
381
|
+
const fc = part.functionCall;
|
|
382
|
+
normalizedContent.push((0, types_1.toolUse)(fc.name, // Gemini doesn't have separate IDs, use function name
|
|
383
|
+
fc.name, (fc.args || {})));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
role,
|
|
388
|
+
content: normalizedContent,
|
|
389
|
+
meta: { provider: "gemini" },
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
/**
|
|
393
|
+
* Create a tool result entry for Gemini
|
|
394
|
+
*/
|
|
395
|
+
toolResultEntry(functionName, output, is_error) {
|
|
396
|
+
return {
|
|
397
|
+
role: "user",
|
|
398
|
+
content: [(0, types_1.toolResult)(functionName, output, is_error)],
|
|
399
|
+
meta: { provider: "gemini" },
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* Extract system message from entries
|
|
404
|
+
*/
|
|
405
|
+
getSystemMessage(entries) {
|
|
406
|
+
const systemEntry = entries.find((e) => e.role === "system");
|
|
407
|
+
if (!systemEntry)
|
|
408
|
+
return undefined;
|
|
409
|
+
return systemEntry.content
|
|
410
|
+
.filter(types_1.isTextContent)
|
|
411
|
+
.map((c) => c.text)
|
|
412
|
+
.join("\n");
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
//# sourceMappingURL=transformers.js.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared History Types
|
|
3
|
+
*
|
|
4
|
+
* These types define a provider-agnostic message format that can be
|
|
5
|
+
* transformed to/from any LLM provider's native format.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Plain text content
|
|
9
|
+
*/
|
|
10
|
+
export type TextContent = {
|
|
11
|
+
type: "text";
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Tool/function call made by the assistant
|
|
16
|
+
*/
|
|
17
|
+
export type ToolUseContent = {
|
|
18
|
+
type: "tool_use";
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
input: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Result of a tool execution
|
|
25
|
+
*/
|
|
26
|
+
export type ToolResultContent = {
|
|
27
|
+
type: "tool_result";
|
|
28
|
+
tool_use_id: string;
|
|
29
|
+
content: string;
|
|
30
|
+
is_error?: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Union of all content types
|
|
34
|
+
*/
|
|
35
|
+
export type MessageContent = TextContent | ToolUseContent | ToolResultContent;
|
|
36
|
+
/**
|
|
37
|
+
* Anthropic-specific metadata
|
|
38
|
+
*/
|
|
39
|
+
export type AnthropicMeta = {
|
|
40
|
+
provider: "anthropic";
|
|
41
|
+
cache_control?: {
|
|
42
|
+
type: "ephemeral";
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* OpenAI-specific metadata
|
|
47
|
+
*/
|
|
48
|
+
export type OpenAiMeta = {
|
|
49
|
+
provider: "openai";
|
|
50
|
+
call_id?: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Mistral-specific metadata
|
|
54
|
+
*/
|
|
55
|
+
export type MistralMeta = {
|
|
56
|
+
provider: "mistral";
|
|
57
|
+
tool_call_id?: string;
|
|
58
|
+
tool_name?: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Gemini-specific metadata
|
|
62
|
+
*/
|
|
63
|
+
export type GeminiMeta = {
|
|
64
|
+
provider: "gemini";
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Union of all provider metadata types
|
|
68
|
+
*/
|
|
69
|
+
export type ProviderMeta = AnthropicMeta | OpenAiMeta | MistralMeta | GeminiMeta;
|
|
70
|
+
/**
|
|
71
|
+
* Valid roles for history entries
|
|
72
|
+
*/
|
|
73
|
+
export type MessageRole = "user" | "assistant" | "system";
|
|
74
|
+
/**
|
|
75
|
+
* A single entry in the conversation history.
|
|
76
|
+
*
|
|
77
|
+
* This is the normalized format that all providers transform to/from.
|
|
78
|
+
*
|
|
79
|
+
* @example Text message
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const entry: HistoryEntry = {
|
|
82
|
+
* role: "user",
|
|
83
|
+
* content: [{ type: "text", text: "Hello" }]
|
|
84
|
+
* };
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example Assistant with tool use
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const entry: HistoryEntry = {
|
|
90
|
+
* role: "assistant",
|
|
91
|
+
* content: [
|
|
92
|
+
* { type: "text", text: "I'll help you with that." },
|
|
93
|
+
* { type: "tool_use", id: "call_123", name: "get_weather", input: { city: "Paris" } }
|
|
94
|
+
* ]
|
|
95
|
+
* };
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Tool result
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const entry: HistoryEntry = {
|
|
101
|
+
* role: "user",
|
|
102
|
+
* content: [{ type: "tool_result", tool_use_id: "call_123", content: "22°C, sunny" }]
|
|
103
|
+
* };
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export type HistoryEntry = {
|
|
107
|
+
role: MessageRole;
|
|
108
|
+
content: MessageContent[];
|
|
109
|
+
meta?: ProviderMeta;
|
|
110
|
+
};
|
|
111
|
+
export declare function isTextContent(content: MessageContent): content is TextContent;
|
|
112
|
+
export declare function isToolUseContent(content: MessageContent): content is ToolUseContent;
|
|
113
|
+
export declare function isToolResultContent(content: MessageContent): content is ToolResultContent;
|
|
114
|
+
/**
|
|
115
|
+
* Create a text content block
|
|
116
|
+
*/
|
|
117
|
+
export declare function text(value: string): TextContent;
|
|
118
|
+
/**
|
|
119
|
+
* Create a tool use content block
|
|
120
|
+
*/
|
|
121
|
+
export declare function toolUse(id: string, name: string, input: Record<string, unknown>): ToolUseContent;
|
|
122
|
+
/**
|
|
123
|
+
* Create a tool result content block
|
|
124
|
+
*/
|
|
125
|
+
export declare function toolResult(tool_use_id: string, content: string, is_error?: boolean): ToolResultContent;
|
|
126
|
+
/**
|
|
127
|
+
* Create a simple text message entry
|
|
128
|
+
*/
|
|
129
|
+
export declare function textMessage(role: MessageRole, value: string): HistoryEntry;
|
|
130
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared History Types
|
|
4
|
+
*
|
|
5
|
+
* These types define a provider-agnostic message format that can be
|
|
6
|
+
* transformed to/from any LLM provider's native format.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isTextContent = isTextContent;
|
|
10
|
+
exports.isToolUseContent = isToolUseContent;
|
|
11
|
+
exports.isToolResultContent = isToolResultContent;
|
|
12
|
+
exports.text = text;
|
|
13
|
+
exports.toolUse = toolUse;
|
|
14
|
+
exports.toolResult = toolResult;
|
|
15
|
+
exports.textMessage = textMessage;
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// Helper Type Guards
|
|
18
|
+
// =============================================================================
|
|
19
|
+
function isTextContent(content) {
|
|
20
|
+
return content.type === "text";
|
|
21
|
+
}
|
|
22
|
+
function isToolUseContent(content) {
|
|
23
|
+
return content.type === "tool_use";
|
|
24
|
+
}
|
|
25
|
+
function isToolResultContent(content) {
|
|
26
|
+
return content.type === "tool_result";
|
|
27
|
+
}
|
|
28
|
+
// =============================================================================
|
|
29
|
+
// Utility Functions
|
|
30
|
+
// =============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Create a text content block
|
|
33
|
+
*/
|
|
34
|
+
function text(value) {
|
|
35
|
+
return { type: "text", text: value };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a tool use content block
|
|
39
|
+
*/
|
|
40
|
+
function toolUse(id, name, input) {
|
|
41
|
+
return { type: "tool_use", id, name, input };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a tool result content block
|
|
45
|
+
*/
|
|
46
|
+
function toolResult(tool_use_id, content, is_error) {
|
|
47
|
+
return { type: "tool_result", tool_use_id, content, is_error };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a simple text message entry
|
|
51
|
+
*/
|
|
52
|
+
function textMessage(role, value) {
|
|
53
|
+
return { role, content: [text(value)] };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./agents/BaseAgent";
|
|
2
|
+
export * from "./agents/anthropic/ClaudeAgent";
|
|
3
|
+
export { OpenAiAgent } from "./agents/openai/OpenAiAgent";
|
|
4
|
+
export { MistralAgent } from "./agents/mistral/MistralAgent";
|
|
5
|
+
export { GeminiAgent } from "./agents/google/GeminiAgent";
|
|
6
|
+
export * from "./agents/model-types";
|
|
7
|
+
export * from "./history/History";
|
|
8
|
+
export * from "./history/types";
|
|
9
|
+
export { anthropicTransformer, openAiTransformer, mistralTransformer, geminiTransformer, } from "./history/transformers";
|
|
10
|
+
export * from "./graph/AgentGraph";
|
|
11
|
+
export * from "./tools/Tool";
|
|
12
|
+
export * from "./viz";
|
|
13
|
+
export * from "./vectorstore";
|
|
14
|
+
export * from "./chunkers";
|
|
15
|
+
export * from "./ingestion";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = exports.GeminiAgent = exports.MistralAgent = exports.OpenAiAgent = void 0;
|
|
18
|
+
// Agents
|
|
19
|
+
__exportStar(require("./agents/BaseAgent"), exports);
|
|
20
|
+
__exportStar(require("./agents/anthropic/ClaudeAgent"), exports);
|
|
21
|
+
var OpenAiAgent_1 = require("./agents/openai/OpenAiAgent");
|
|
22
|
+
Object.defineProperty(exports, "OpenAiAgent", { enumerable: true, get: function () { return OpenAiAgent_1.OpenAiAgent; } });
|
|
23
|
+
var MistralAgent_1 = require("./agents/mistral/MistralAgent");
|
|
24
|
+
Object.defineProperty(exports, "MistralAgent", { enumerable: true, get: function () { return MistralAgent_1.MistralAgent; } });
|
|
25
|
+
var GeminiAgent_1 = require("./agents/google/GeminiAgent");
|
|
26
|
+
Object.defineProperty(exports, "GeminiAgent", { enumerable: true, get: function () { return GeminiAgent_1.GeminiAgent; } });
|
|
27
|
+
__exportStar(require("./agents/model-types"), exports);
|
|
28
|
+
// History
|
|
29
|
+
__exportStar(require("./history/History"), exports);
|
|
30
|
+
__exportStar(require("./history/types"), exports);
|
|
31
|
+
var transformers_1 = require("./history/transformers");
|
|
32
|
+
Object.defineProperty(exports, "anthropicTransformer", { enumerable: true, get: function () { return transformers_1.anthropicTransformer; } });
|
|
33
|
+
Object.defineProperty(exports, "openAiTransformer", { enumerable: true, get: function () { return transformers_1.openAiTransformer; } });
|
|
34
|
+
Object.defineProperty(exports, "mistralTransformer", { enumerable: true, get: function () { return transformers_1.mistralTransformer; } });
|
|
35
|
+
Object.defineProperty(exports, "geminiTransformer", { enumerable: true, get: function () { return transformers_1.geminiTransformer; } });
|
|
36
|
+
// Graph
|
|
37
|
+
__exportStar(require("./graph/AgentGraph"), exports);
|
|
38
|
+
// Tools
|
|
39
|
+
__exportStar(require("./tools/Tool"), exports);
|
|
40
|
+
// Visualization
|
|
41
|
+
__exportStar(require("./viz"), exports);
|
|
42
|
+
// Vector Store
|
|
43
|
+
__exportStar(require("./vectorstore"), exports);
|
|
44
|
+
// Chunkers
|
|
45
|
+
__exportStar(require("./chunkers"), exports);
|
|
46
|
+
// Ingestion
|
|
47
|
+
__exportStar(require("./ingestion"), exports);
|
|
48
|
+
//# sourceMappingURL=index.js.map
|