elsium-ai 0.4.2 → 0.5.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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +524 -13
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export { ElsiumError, ok, err, isOk, isErr, unwrap, unwrapOr, tryCatch, tryCatch
|
|
|
13
13
|
export type { Role, ContentPart, TextContent, ImageContent, AudioContent, DocumentContent, Message, ToolCall, ToolResult, TokenUsage, CostBreakdown, StopReason, LLMResponse, StreamEvent, XRayData, StreamCheckpoint, ProviderConfig, CompletionRequest, ToolDefinition, TenantContext, Middleware, Result, Ok, Err, ElsiumStream, ResilientStreamOptions, LogLevel, Logger, ErrorCode, Registry, ContextStrategy, ContextManagerConfig, ContextManager, } from '@elsium-ai/core';
|
|
14
14
|
export { gateway, registerProviderFactory, registerProvider, getProviderFactory, listProviders, registerProviderMetadata, getProviderMetadata, calculateCost, registerPricing, composeMiddleware, loggingMiddleware, costTrackingMiddleware, xrayMiddleware, createAnthropicProvider, createOpenAIProvider, createGoogleProvider, createProviderMesh, securityMiddleware, detectPromptInjection, detectJailbreak, redactSecrets, checkBlockedPatterns, cacheMiddleware, createInMemoryCache, outputGuardrailMiddleware, createBatch, } from '@elsium-ai/gateway';
|
|
15
15
|
export type { LLMProvider, ProviderFactory, ProviderMetadata, ModelPricing, ModelTier, Gateway, GatewayConfig, XRayStore, ProviderMeshConfig, ProviderEntry, RoutingStrategy, ProviderMesh, SecurityMiddlewareConfig, SecurityViolation, SecurityResult, CacheAdapter, CacheStats, CacheMiddlewareConfig, OutputGuardrailConfig, OutputGuardrailRule, OutputViolation, BatchConfig, BatchResult, BatchResultItem, } from '@elsium-ai/gateway';
|
|
16
|
-
export { defineAgent, runSequential, runParallel, runSupervisor, createMemory, createSemanticValidator, createAgentSecurity, createConfidenceScorer, executeStateMachine, createInMemoryMemoryStore, createSqliteMemoryStore, } from '@elsium-ai/agents';
|
|
17
|
-
export type { Agent, AgentDependencies, AgentConfig, AgentResult, AgentRunOptions, GuardrailConfig, AgentHooks, Memory, MemoryConfig, SemanticGuardrailConfig, SemanticCheck, SemanticCheckResult, SemanticValidationResult, SemanticValidator, AgentSecurityConfig, AgentSecurityResult, ConfidenceConfig, ConfidenceResult, StateDefinition, StateHistoryEntry, StateMachineResult, MemoryStore, SqliteMemoryStoreConfig, } from '@elsium-ai/agents';
|
|
16
|
+
export { defineAgent, runSequential, runParallel, runSupervisor, createMemory, createSemanticValidator, createAgentSecurity, createConfidenceScorer, executeStateMachine, createInMemoryMemoryStore, createSqliteMemoryStore, createAgentStream, createThread, loadThread, createInMemoryThreadStore, createAsyncAgent, } from '@elsium-ai/agents';
|
|
17
|
+
export type { Agent, AgentDependencies, AgentConfig, AgentResult, AgentRunOptions, GuardrailConfig, AgentHooks, Memory, MemoryConfig, SemanticGuardrailConfig, SemanticCheck, SemanticCheckResult, SemanticValidationResult, SemanticValidator, AgentSecurityConfig, AgentSecurityResult, ConfidenceConfig, ConfidenceResult, StateDefinition, StateHistoryEntry, StateMachineResult, MemoryStore, SqliteMemoryStoreConfig, AgentStreamEvent, AgentStream, StreamingAgentDependencies, Thread, ThreadConfig, ThreadStore, ThreadSnapshot, ThreadSummary, AsyncAgent, AsyncAgentConfig, AsyncAgentRunOptions, AgentTask, TaskStatus, TaskProgressEvent, } from '@elsium-ai/agents';
|
|
18
18
|
export { defineTool, createToolkit, httpFetchTool, calculatorTool, jsonParseTool, currentTimeTool, formatToolResult, formatToolResultAsText, } from '@elsium-ai/tools';
|
|
19
19
|
export type { Tool, ToolConfig, ToolContext, ToolExecutionResult, Toolkit, } from '@elsium-ai/tools';
|
|
20
20
|
export { rag, createInMemoryStore, createOpenAIEmbeddings, createMockEmbeddings, vectorStoreRegistry, embeddingProviderRegistry, createPgVectorStore, } from '@elsium-ai/rag';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAEN,WAAW,EAEX,EAAE,EACF,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EAEZ,YAAY,EAEZ,YAAY,EAEZ,GAAG,EACH,SAAS,EACT,OAAO,EAEP,UAAU,EACV,eAAe,EACf,WAAW,EACX,KAAK,EACL,KAAK,EAEL,eAAe,EAEf,cAAc,EAEd,WAAW,EACX,oBAAoB,GACpB,MAAM,iBAAiB,CAAA;AAExB,YAAY,EAEX,IAAI,EACJ,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,UAAU,EAEV,MAAM,EACN,EAAE,EACF,GAAG,EAEH,YAAY,EACZ,sBAAsB,EAEtB,QAAQ,EACR,MAAM,EAEN,SAAS,EAET,QAAQ,EAER,eAAe,EACf,oBAAoB,EACpB,cAAc,GACd,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACN,OAAO,EACP,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,oBAAoB,EAEpB,eAAe,EACf,mBAAmB,EAEnB,yBAAyB,EAEzB,WAAW,GACX,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACX,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,OAAO,EACP,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EAEd,YAAY,EACZ,UAAU,EACV,qBAAqB,EAErB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EAEf,WAAW,EACX,WAAW,EACX,eAAe,GACf,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EACN,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EAEnB,yBAAyB,EACzB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAEN,WAAW,EAEX,EAAE,EACF,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EAEZ,YAAY,EAEZ,YAAY,EAEZ,GAAG,EACH,SAAS,EACT,OAAO,EAEP,UAAU,EACV,eAAe,EACf,WAAW,EACX,KAAK,EACL,KAAK,EAEL,eAAe,EAEf,cAAc,EAEd,WAAW,EACX,oBAAoB,GACpB,MAAM,iBAAiB,CAAA;AAExB,YAAY,EAEX,IAAI,EACJ,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,UAAU,EAEV,MAAM,EACN,EAAE,EACF,GAAG,EAEH,YAAY,EACZ,sBAAsB,EAEtB,QAAQ,EACR,MAAM,EAE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,EACR,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,EACd,YAAY,GACZ,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -974,7 +974,8 @@ function createShutdownManager(config) {
|
|
|
974
974
|
// ../gateway/src/provider.ts
|
|
975
975
|
var providerRegistry = new Map;
|
|
976
976
|
var metadataRegistry = new Map;
|
|
977
|
-
function registerProvider(name,
|
|
977
|
+
function registerProvider(name, factoryOrProvider) {
|
|
978
|
+
const factory = typeof factoryOrProvider === "function" ? factoryOrProvider : () => factoryOrProvider;
|
|
978
979
|
providerRegistry.set(name, factory);
|
|
979
980
|
}
|
|
980
981
|
function getProviderFactory(name) {
|
|
@@ -2623,27 +2624,27 @@ var JAILBREAK_PATTERNS = [
|
|
|
2623
2624
|
];
|
|
2624
2625
|
var SECRET_PATTERNS = [
|
|
2625
2626
|
{
|
|
2626
|
-
pattern: /\bsk-[a-zA-Z0-9_-]{
|
|
2627
|
+
pattern: /\bsk-[a-zA-Z0-9_-]{8,}\b/g,
|
|
2627
2628
|
detail: "API secret key detected",
|
|
2628
2629
|
replacement: "[REDACTED_API_KEY]"
|
|
2629
2630
|
},
|
|
2630
2631
|
{
|
|
2631
|
-
pattern: /\bpk-[a-zA-Z0-9_-]{
|
|
2632
|
+
pattern: /\bpk-[a-zA-Z0-9_-]{8,}\b/g,
|
|
2632
2633
|
detail: "API public key detected",
|
|
2633
2634
|
replacement: "[REDACTED_API_KEY]"
|
|
2634
2635
|
},
|
|
2635
2636
|
{
|
|
2636
|
-
pattern: /\bghp_[a-zA-Z0-9]{
|
|
2637
|
+
pattern: /\bghp_[a-zA-Z0-9]{8,}\b/g,
|
|
2637
2638
|
detail: "GitHub personal access token detected",
|
|
2638
2639
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
2639
2640
|
},
|
|
2640
2641
|
{
|
|
2641
|
-
pattern: /\bgho_[a-zA-Z0-9]{
|
|
2642
|
+
pattern: /\bgho_[a-zA-Z0-9]{8,}\b/g,
|
|
2642
2643
|
detail: "GitHub OAuth token detected",
|
|
2643
2644
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
2644
2645
|
},
|
|
2645
2646
|
{
|
|
2646
|
-
pattern: /\bgithub_pat_[a-zA-Z0-9_]{
|
|
2647
|
+
pattern: /\bgithub_pat_[a-zA-Z0-9_]{8,}\b/g,
|
|
2647
2648
|
detail: "GitHub fine-grained token detected",
|
|
2648
2649
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
2649
2650
|
},
|
|
@@ -8123,27 +8124,27 @@ var JAILBREAK_PATTERNS2 = [
|
|
|
8123
8124
|
];
|
|
8124
8125
|
var SECRET_PATTERNS3 = [
|
|
8125
8126
|
{
|
|
8126
|
-
pattern: /\bsk-[a-zA-Z0-9_-]{
|
|
8127
|
+
pattern: /\bsk-[a-zA-Z0-9_-]{8,}\b/g,
|
|
8127
8128
|
detail: "API secret key detected",
|
|
8128
8129
|
replacement: "[REDACTED_API_KEY]"
|
|
8129
8130
|
},
|
|
8130
8131
|
{
|
|
8131
|
-
pattern: /\bpk-[a-zA-Z0-9_-]{
|
|
8132
|
+
pattern: /\bpk-[a-zA-Z0-9_-]{8,}\b/g,
|
|
8132
8133
|
detail: "API public key detected",
|
|
8133
8134
|
replacement: "[REDACTED_API_KEY]"
|
|
8134
8135
|
},
|
|
8135
8136
|
{
|
|
8136
|
-
pattern: /\bghp_[a-zA-Z0-9]{
|
|
8137
|
+
pattern: /\bghp_[a-zA-Z0-9]{8,}\b/g,
|
|
8137
8138
|
detail: "GitHub personal access token detected",
|
|
8138
8139
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
8139
8140
|
},
|
|
8140
8141
|
{
|
|
8141
|
-
pattern: /\bgho_[a-zA-Z0-9]{
|
|
8142
|
+
pattern: /\bgho_[a-zA-Z0-9]{8,}\b/g,
|
|
8142
8143
|
detail: "GitHub OAuth token detected",
|
|
8143
8144
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
8144
8145
|
},
|
|
8145
8146
|
{
|
|
8146
|
-
pattern: /\bgithub_pat_[a-zA-Z0-9_]{
|
|
8147
|
+
pattern: /\bgithub_pat_[a-zA-Z0-9_]{8,}\b/g,
|
|
8147
8148
|
detail: "GitHub fine-grained token detected",
|
|
8148
8149
|
replacement: "[REDACTED_GITHUB_TOKEN]"
|
|
8149
8150
|
},
|
|
@@ -8669,6 +8670,219 @@ async function executeToolCalls(toolCalls, toolMap, history, signal, hooks, appr
|
|
|
8669
8670
|
return results;
|
|
8670
8671
|
}
|
|
8671
8672
|
|
|
8673
|
+
// ../agents/src/streaming.ts
|
|
8674
|
+
async function accumulateStreamedResponse(stream, emit) {
|
|
8675
|
+
let textContent = "";
|
|
8676
|
+
const toolCalls = [];
|
|
8677
|
+
const toolArgBuffers = {};
|
|
8678
|
+
let usage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
8679
|
+
let stopReason = "end_turn";
|
|
8680
|
+
for await (const event of stream) {
|
|
8681
|
+
switch (event.type) {
|
|
8682
|
+
case "text_delta":
|
|
8683
|
+
textContent += event.text;
|
|
8684
|
+
emit({ type: "text_delta", text: event.text });
|
|
8685
|
+
break;
|
|
8686
|
+
case "tool_call_start":
|
|
8687
|
+
toolArgBuffers[event.toolCall.id] = "";
|
|
8688
|
+
toolCalls.push({ id: event.toolCall.id, name: event.toolCall.name, arguments: {} });
|
|
8689
|
+
emit({ type: "tool_call_start", toolCall: event.toolCall });
|
|
8690
|
+
break;
|
|
8691
|
+
case "tool_call_delta":
|
|
8692
|
+
if (toolArgBuffers[event.toolCallId] !== undefined) {
|
|
8693
|
+
toolArgBuffers[event.toolCallId] += event.arguments;
|
|
8694
|
+
}
|
|
8695
|
+
emit({
|
|
8696
|
+
type: "tool_call_delta",
|
|
8697
|
+
toolCallId: event.toolCallId,
|
|
8698
|
+
arguments: event.arguments
|
|
8699
|
+
});
|
|
8700
|
+
break;
|
|
8701
|
+
case "tool_call_end": {
|
|
8702
|
+
const tc = toolCalls.find((t) => t.id === event.toolCallId);
|
|
8703
|
+
if (tc && toolArgBuffers[event.toolCallId]) {
|
|
8704
|
+
try {
|
|
8705
|
+
tc.arguments = JSON.parse(toolArgBuffers[event.toolCallId]);
|
|
8706
|
+
} catch {
|
|
8707
|
+
tc.arguments = {};
|
|
8708
|
+
}
|
|
8709
|
+
}
|
|
8710
|
+
emit({ type: "tool_call_end", toolCallId: event.toolCallId });
|
|
8711
|
+
break;
|
|
8712
|
+
}
|
|
8713
|
+
case "message_end":
|
|
8714
|
+
usage = event.usage;
|
|
8715
|
+
stopReason = event.stopReason;
|
|
8716
|
+
break;
|
|
8717
|
+
}
|
|
8718
|
+
}
|
|
8719
|
+
return {
|
|
8720
|
+
message: {
|
|
8721
|
+
role: "assistant",
|
|
8722
|
+
content: textContent,
|
|
8723
|
+
...toolCalls.length ? { toolCalls } : {}
|
|
8724
|
+
},
|
|
8725
|
+
usage,
|
|
8726
|
+
stopReason
|
|
8727
|
+
};
|
|
8728
|
+
}
|
|
8729
|
+
async function executeStreamToolCalls(toolCalls, ctx, emit) {
|
|
8730
|
+
const results = [];
|
|
8731
|
+
const history = [];
|
|
8732
|
+
for (const tc of toolCalls) {
|
|
8733
|
+
const tool = ctx.toolMap.get(tc.name);
|
|
8734
|
+
if (!tool) {
|
|
8735
|
+
const errorResult = {
|
|
8736
|
+
success: false,
|
|
8737
|
+
error: `Unknown tool: ${tc.name}. Available: ${Array.from(ctx.toolMap.keys()).join(", ")}`,
|
|
8738
|
+
toolCallId: tc.id,
|
|
8739
|
+
durationMs: 0
|
|
8740
|
+
};
|
|
8741
|
+
emit({ type: "tool_result", toolCallId: tc.id, name: tc.name, result: errorResult });
|
|
8742
|
+
history.push({ name: tc.name, arguments: tc.arguments, result: errorResult });
|
|
8743
|
+
results.push(formatToolResult(errorResult));
|
|
8744
|
+
continue;
|
|
8745
|
+
}
|
|
8746
|
+
const result = await tool.execute(tc.arguments, {
|
|
8747
|
+
toolCallId: tc.id,
|
|
8748
|
+
signal: ctx.options.signal
|
|
8749
|
+
});
|
|
8750
|
+
emit({ type: "tool_result", toolCallId: tc.id, name: tc.name, result });
|
|
8751
|
+
history.push({ name: tc.name, arguments: tc.arguments, result });
|
|
8752
|
+
results.push(formatToolResult(result));
|
|
8753
|
+
}
|
|
8754
|
+
return {
|
|
8755
|
+
toolMessage: { role: "tool", content: "", toolResults: results },
|
|
8756
|
+
history
|
|
8757
|
+
};
|
|
8758
|
+
}
|
|
8759
|
+
function createAgentStream(messages, ctx) {
|
|
8760
|
+
let resolveResult;
|
|
8761
|
+
let rejectResult;
|
|
8762
|
+
const resultPromise = new Promise((resolve2, reject) => {
|
|
8763
|
+
resolveResult = resolve2;
|
|
8764
|
+
rejectResult = reject;
|
|
8765
|
+
});
|
|
8766
|
+
const events = [];
|
|
8767
|
+
let resolve = null;
|
|
8768
|
+
let done = false;
|
|
8769
|
+
function emit(event) {
|
|
8770
|
+
if (resolve) {
|
|
8771
|
+
const r = resolve;
|
|
8772
|
+
resolve = null;
|
|
8773
|
+
r({ value: event, done: false });
|
|
8774
|
+
} else {
|
|
8775
|
+
events.push(event);
|
|
8776
|
+
}
|
|
8777
|
+
}
|
|
8778
|
+
function finish() {
|
|
8779
|
+
done = true;
|
|
8780
|
+
if (resolve) {
|
|
8781
|
+
const r = resolve;
|
|
8782
|
+
resolve = null;
|
|
8783
|
+
r({ value: undefined, done: true });
|
|
8784
|
+
}
|
|
8785
|
+
}
|
|
8786
|
+
runStreamLoop(messages, ctx, emit).then((agentResult) => {
|
|
8787
|
+
resolveResult(agentResult);
|
|
8788
|
+
finish();
|
|
8789
|
+
}).catch((err2) => {
|
|
8790
|
+
const error = err2 instanceof Error ? err2 : new Error(String(err2));
|
|
8791
|
+
emit({ type: "error", error });
|
|
8792
|
+
rejectResult?.(error);
|
|
8793
|
+
finish();
|
|
8794
|
+
});
|
|
8795
|
+
resultPromise.catch(() => {});
|
|
8796
|
+
const iterable = {
|
|
8797
|
+
[Symbol.asyncIterator]() {
|
|
8798
|
+
return {
|
|
8799
|
+
next() {
|
|
8800
|
+
const next = events.shift();
|
|
8801
|
+
if (next) {
|
|
8802
|
+
return Promise.resolve({ value: next, done: false });
|
|
8803
|
+
}
|
|
8804
|
+
if (done) {
|
|
8805
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
8806
|
+
}
|
|
8807
|
+
return new Promise((r) => {
|
|
8808
|
+
resolve = r;
|
|
8809
|
+
});
|
|
8810
|
+
}
|
|
8811
|
+
};
|
|
8812
|
+
},
|
|
8813
|
+
result() {
|
|
8814
|
+
return resultPromise;
|
|
8815
|
+
}
|
|
8816
|
+
};
|
|
8817
|
+
return iterable;
|
|
8818
|
+
}
|
|
8819
|
+
async function runStreamLoop(messages, ctx, emit) {
|
|
8820
|
+
const { config, deps, memory, options } = ctx;
|
|
8821
|
+
const traceId = options.traceId ?? generateTraceId();
|
|
8822
|
+
let totalInputTokens = 0;
|
|
8823
|
+
let totalOutputTokens = 0;
|
|
8824
|
+
const totalCost = 0;
|
|
8825
|
+
let iterations = 0;
|
|
8826
|
+
const allToolCalls = [];
|
|
8827
|
+
const scopedMessages = [...memory.getMessages()];
|
|
8828
|
+
const conversationMessages = [...scopedMessages, ...messages];
|
|
8829
|
+
while (iterations < ctx.maxIterations) {
|
|
8830
|
+
iterations++;
|
|
8831
|
+
if (options.signal?.aborted) {
|
|
8832
|
+
throw new ElsiumError({
|
|
8833
|
+
code: "VALIDATION_ERROR",
|
|
8834
|
+
message: `Agent "${config.name}" was aborted`,
|
|
8835
|
+
retryable: false
|
|
8836
|
+
});
|
|
8837
|
+
}
|
|
8838
|
+
if (totalInputTokens + totalOutputTokens > ctx.maxTokenBudget) {
|
|
8839
|
+
throw ElsiumError.budgetExceeded(totalInputTokens + totalOutputTokens, ctx.maxTokenBudget);
|
|
8840
|
+
}
|
|
8841
|
+
emit({ type: "iteration_start", iteration: iterations });
|
|
8842
|
+
const request = {
|
|
8843
|
+
messages: conversationMessages,
|
|
8844
|
+
model: config.model,
|
|
8845
|
+
system: config.system,
|
|
8846
|
+
tools: config.tools?.map((t) => t.toDefinition())
|
|
8847
|
+
};
|
|
8848
|
+
const llmStream = deps.stream(request);
|
|
8849
|
+
const { message, usage, stopReason } = await accumulateStreamedResponse(llmStream, emit);
|
|
8850
|
+
totalInputTokens += usage.inputTokens;
|
|
8851
|
+
totalOutputTokens += usage.outputTokens;
|
|
8852
|
+
conversationMessages.push(message);
|
|
8853
|
+
if (!message.toolCalls?.length || stopReason !== "tool_use") {
|
|
8854
|
+
emit({ type: "iteration_end", iteration: iterations });
|
|
8855
|
+
for (const msg of conversationMessages.slice(scopedMessages.length)) {
|
|
8856
|
+
memory.add(msg);
|
|
8857
|
+
}
|
|
8858
|
+
const agentResult = {
|
|
8859
|
+
message,
|
|
8860
|
+
usage: {
|
|
8861
|
+
totalInputTokens,
|
|
8862
|
+
totalOutputTokens,
|
|
8863
|
+
totalTokens: totalInputTokens + totalOutputTokens,
|
|
8864
|
+
totalCost,
|
|
8865
|
+
iterations
|
|
8866
|
+
},
|
|
8867
|
+
toolCalls: allToolCalls,
|
|
8868
|
+
traceId
|
|
8869
|
+
};
|
|
8870
|
+
emit({ type: "agent_end", result: agentResult });
|
|
8871
|
+
return agentResult;
|
|
8872
|
+
}
|
|
8873
|
+
const { toolMessage, history } = await executeStreamToolCalls(message.toolCalls, ctx, emit);
|
|
8874
|
+
allToolCalls.push(...history);
|
|
8875
|
+
conversationMessages.push(toolMessage);
|
|
8876
|
+
emit({ type: "iteration_end", iteration: iterations });
|
|
8877
|
+
}
|
|
8878
|
+
throw new ElsiumError({
|
|
8879
|
+
code: "MAX_ITERATIONS",
|
|
8880
|
+
message: `Agent "${config.name}" reached maximum iterations (${ctx.maxIterations})`,
|
|
8881
|
+
retryable: false,
|
|
8882
|
+
metadata: { iterations, maxIterations: ctx.maxIterations }
|
|
8883
|
+
});
|
|
8884
|
+
}
|
|
8885
|
+
|
|
8672
8886
|
// ../agents/src/agent.ts
|
|
8673
8887
|
async function safeHook2(fn) {
|
|
8674
8888
|
if (!fn)
|
|
@@ -8682,7 +8896,10 @@ function resolveDependencies(config, deps) {
|
|
|
8682
8896
|
return deps;
|
|
8683
8897
|
if (typeof config.provider === "object" && config.provider !== null) {
|
|
8684
8898
|
const provider = config.provider;
|
|
8685
|
-
return {
|
|
8899
|
+
return {
|
|
8900
|
+
complete: (req) => provider.complete(req),
|
|
8901
|
+
stream: (req) => provider.stream(req)
|
|
8902
|
+
};
|
|
8686
8903
|
}
|
|
8687
8904
|
if (!config.provider || !config.apiKey) {
|
|
8688
8905
|
throw ElsiumError.validation("Either provide AgentDependencies as second argument, set provider and apiKey in config, or pass an LLMProvider object as provider");
|
|
@@ -8693,7 +8910,10 @@ function resolveDependencies(config, deps) {
|
|
|
8693
8910
|
baseUrl: config.baseUrl,
|
|
8694
8911
|
model: config.model
|
|
8695
8912
|
});
|
|
8696
|
-
return {
|
|
8913
|
+
return {
|
|
8914
|
+
complete: (req) => gw.complete(req),
|
|
8915
|
+
stream: (req) => gw.stream(req)
|
|
8916
|
+
};
|
|
8697
8917
|
}
|
|
8698
8918
|
function defineAgent(config, deps) {
|
|
8699
8919
|
const resolvedDeps = resolveDependencies(config, deps);
|
|
@@ -8933,6 +9153,23 @@ function defineAgent(config, deps) {
|
|
|
8933
9153
|
const userMessage = { role: "user", content: input };
|
|
8934
9154
|
return executeLoop([userMessage], options);
|
|
8935
9155
|
},
|
|
9156
|
+
stream(input, options = {}) {
|
|
9157
|
+
validateInputText(input);
|
|
9158
|
+
const streamDeps = resolvedDeps;
|
|
9159
|
+
if (!streamDeps.stream) {
|
|
9160
|
+
throw ElsiumError.validation("Streaming requires a stream function in agent dependencies. " + "Pass { complete, stream } or use a provider that supports streaming.");
|
|
9161
|
+
}
|
|
9162
|
+
const userMessage = { role: "user", content: input };
|
|
9163
|
+
return createAgentStream([userMessage], {
|
|
9164
|
+
config,
|
|
9165
|
+
deps: streamDeps,
|
|
9166
|
+
memory,
|
|
9167
|
+
toolMap,
|
|
9168
|
+
options,
|
|
9169
|
+
maxIterations: guardrails.maxIterations,
|
|
9170
|
+
maxTokenBudget: guardrails.maxTokenBudget
|
|
9171
|
+
});
|
|
9172
|
+
},
|
|
8936
9173
|
async chat(messages, options = {}) {
|
|
8937
9174
|
for (const msg of messages) {
|
|
8938
9175
|
if (msg.role !== "user")
|
|
@@ -9129,6 +9366,275 @@ async function runSupervisor(supervisor, workers, input, options) {
|
|
|
9129
9366
|
};
|
|
9130
9367
|
return supervisor.run(supervisorInput, agentOptions);
|
|
9131
9368
|
}
|
|
9369
|
+
// ../agents/src/thread.ts
|
|
9370
|
+
function createThread(config) {
|
|
9371
|
+
const id = config.id ?? generateId("thread");
|
|
9372
|
+
const messages = [];
|
|
9373
|
+
const metadata = { ...config.metadata };
|
|
9374
|
+
const createdAt = Date.now();
|
|
9375
|
+
let updatedAt = createdAt;
|
|
9376
|
+
function addMessage(message) {
|
|
9377
|
+
messages.push(message);
|
|
9378
|
+
updatedAt = Date.now();
|
|
9379
|
+
if (config.store) {
|
|
9380
|
+
config.store.save({
|
|
9381
|
+
id,
|
|
9382
|
+
messages: [...messages],
|
|
9383
|
+
createdAt,
|
|
9384
|
+
updatedAt,
|
|
9385
|
+
metadata
|
|
9386
|
+
}).catch(() => {});
|
|
9387
|
+
}
|
|
9388
|
+
}
|
|
9389
|
+
return {
|
|
9390
|
+
id,
|
|
9391
|
+
metadata,
|
|
9392
|
+
async send(input, options = {}) {
|
|
9393
|
+
const userMessage = { role: "user", content: input };
|
|
9394
|
+
addMessage(userMessage);
|
|
9395
|
+
const result = await config.agent.chat([...messages], options);
|
|
9396
|
+
addMessage(result.message);
|
|
9397
|
+
return result;
|
|
9398
|
+
},
|
|
9399
|
+
stream(input, options = {}) {
|
|
9400
|
+
const userMessage = { role: "user", content: input };
|
|
9401
|
+
addMessage(userMessage);
|
|
9402
|
+
const agentStream = config.agent.stream(input, options);
|
|
9403
|
+
const originalResult = agentStream.result.bind(agentStream);
|
|
9404
|
+
const wrappedStream = {
|
|
9405
|
+
[Symbol.asyncIterator]() {
|
|
9406
|
+
const inner = agentStream[Symbol.asyncIterator]();
|
|
9407
|
+
return {
|
|
9408
|
+
async next() {
|
|
9409
|
+
const iterResult = await inner.next();
|
|
9410
|
+
if (!iterResult.done && iterResult.value.type === "agent_end") {
|
|
9411
|
+
addMessage(iterResult.value.result.message);
|
|
9412
|
+
}
|
|
9413
|
+
return iterResult;
|
|
9414
|
+
}
|
|
9415
|
+
};
|
|
9416
|
+
},
|
|
9417
|
+
async result() {
|
|
9418
|
+
const r = await originalResult();
|
|
9419
|
+
return r;
|
|
9420
|
+
}
|
|
9421
|
+
};
|
|
9422
|
+
return wrappedStream;
|
|
9423
|
+
},
|
|
9424
|
+
getMessages() {
|
|
9425
|
+
return [...messages];
|
|
9426
|
+
},
|
|
9427
|
+
addMessage(message) {
|
|
9428
|
+
addMessage(message);
|
|
9429
|
+
},
|
|
9430
|
+
fork(options) {
|
|
9431
|
+
const forked = createThread({
|
|
9432
|
+
id: options?.id,
|
|
9433
|
+
agent: config.agent,
|
|
9434
|
+
metadata: { ...metadata, forkedFrom: id },
|
|
9435
|
+
store: config.store
|
|
9436
|
+
});
|
|
9437
|
+
for (const msg of messages) {
|
|
9438
|
+
forked.addMessage({ ...msg });
|
|
9439
|
+
}
|
|
9440
|
+
return forked;
|
|
9441
|
+
},
|
|
9442
|
+
clear() {
|
|
9443
|
+
messages.length = 0;
|
|
9444
|
+
updatedAt = Date.now();
|
|
9445
|
+
},
|
|
9446
|
+
async save() {
|
|
9447
|
+
if (!config.store)
|
|
9448
|
+
return;
|
|
9449
|
+
await config.store.save({
|
|
9450
|
+
id,
|
|
9451
|
+
messages: [...messages],
|
|
9452
|
+
createdAt,
|
|
9453
|
+
updatedAt,
|
|
9454
|
+
metadata
|
|
9455
|
+
});
|
|
9456
|
+
}
|
|
9457
|
+
};
|
|
9458
|
+
}
|
|
9459
|
+
async function loadThread(threadId, config) {
|
|
9460
|
+
const snapshot = await config.store.load(threadId);
|
|
9461
|
+
if (!snapshot)
|
|
9462
|
+
return null;
|
|
9463
|
+
const thread = createThread({
|
|
9464
|
+
id: threadId,
|
|
9465
|
+
agent: config.agent,
|
|
9466
|
+
metadata: snapshot.metadata,
|
|
9467
|
+
store: config.store
|
|
9468
|
+
});
|
|
9469
|
+
for (const msg of snapshot.messages) {
|
|
9470
|
+
thread.addMessage(msg);
|
|
9471
|
+
}
|
|
9472
|
+
return thread;
|
|
9473
|
+
}
|
|
9474
|
+
function createInMemoryThreadStore() {
|
|
9475
|
+
const store = new Map;
|
|
9476
|
+
return {
|
|
9477
|
+
async load(threadId) {
|
|
9478
|
+
const snapshot = store.get(threadId);
|
|
9479
|
+
if (!snapshot)
|
|
9480
|
+
return null;
|
|
9481
|
+
return { ...snapshot, messages: [...snapshot.messages] };
|
|
9482
|
+
},
|
|
9483
|
+
async save(snapshot) {
|
|
9484
|
+
store.set(snapshot.id, { ...snapshot, messages: [...snapshot.messages] });
|
|
9485
|
+
},
|
|
9486
|
+
async delete(threadId) {
|
|
9487
|
+
store.delete(threadId);
|
|
9488
|
+
},
|
|
9489
|
+
async list(options) {
|
|
9490
|
+
const limit = options?.limit ?? 50;
|
|
9491
|
+
const offset = options?.offset ?? 0;
|
|
9492
|
+
const entries = [...store.values()].sort((a, b) => b.updatedAt - a.updatedAt).slice(offset, offset + limit);
|
|
9493
|
+
return entries.map((s) => {
|
|
9494
|
+
const lastMsg = s.messages[s.messages.length - 1];
|
|
9495
|
+
const lastMessage = lastMsg ? typeof lastMsg.content === "string" ? lastMsg.content.slice(0, 100) : undefined : undefined;
|
|
9496
|
+
return {
|
|
9497
|
+
id: s.id,
|
|
9498
|
+
messageCount: s.messages.length,
|
|
9499
|
+
createdAt: s.createdAt,
|
|
9500
|
+
updatedAt: s.updatedAt,
|
|
9501
|
+
lastMessage,
|
|
9502
|
+
metadata: s.metadata
|
|
9503
|
+
};
|
|
9504
|
+
});
|
|
9505
|
+
}
|
|
9506
|
+
};
|
|
9507
|
+
}
|
|
9508
|
+
// ../agents/src/async-agent.ts
|
|
9509
|
+
function createAsyncAgent(config) {
|
|
9510
|
+
const tasks = new Map;
|
|
9511
|
+
function emitProgress(task, event) {
|
|
9512
|
+
try {
|
|
9513
|
+
config.onProgress?.(toPublicTask(task), event);
|
|
9514
|
+
} catch {}
|
|
9515
|
+
}
|
|
9516
|
+
function toPublicTask(task) {
|
|
9517
|
+
return {
|
|
9518
|
+
id: task.id,
|
|
9519
|
+
agentName: task.agentName,
|
|
9520
|
+
input: task.input,
|
|
9521
|
+
status: task.status,
|
|
9522
|
+
result: task.result,
|
|
9523
|
+
error: task.error,
|
|
9524
|
+
createdAt: task.createdAt,
|
|
9525
|
+
startedAt: task.startedAt,
|
|
9526
|
+
completedAt: task.completedAt,
|
|
9527
|
+
metadata: task.metadata,
|
|
9528
|
+
cancel() {
|
|
9529
|
+
if (task.status === "pending" || task.status === "running") {
|
|
9530
|
+
task.status = "cancelled";
|
|
9531
|
+
task.completedAt = Date.now();
|
|
9532
|
+
task.abortController.abort();
|
|
9533
|
+
emitProgress(task, { type: "cancelled", taskId: task.id });
|
|
9534
|
+
task.reject(new ElsiumError({
|
|
9535
|
+
code: "VALIDATION_ERROR",
|
|
9536
|
+
message: `Task ${task.id} was cancelled`,
|
|
9537
|
+
retryable: false
|
|
9538
|
+
}));
|
|
9539
|
+
}
|
|
9540
|
+
},
|
|
9541
|
+
wait() {
|
|
9542
|
+
return task.promise;
|
|
9543
|
+
}
|
|
9544
|
+
};
|
|
9545
|
+
}
|
|
9546
|
+
async function executeTask(task) {
|
|
9547
|
+
task.status = "running";
|
|
9548
|
+
task.startedAt = Date.now();
|
|
9549
|
+
emitProgress(task, { type: "started", taskId: task.id });
|
|
9550
|
+
try {
|
|
9551
|
+
const result = await config.agent.run(task.input, {
|
|
9552
|
+
signal: task.abortController.signal,
|
|
9553
|
+
traceId: task.metadata.traceId
|
|
9554
|
+
});
|
|
9555
|
+
if (task.status === "cancelled")
|
|
9556
|
+
return;
|
|
9557
|
+
task.status = "completed";
|
|
9558
|
+
task.result = result;
|
|
9559
|
+
task.completedAt = Date.now();
|
|
9560
|
+
emitProgress(task, { type: "completed", taskId: task.id, result });
|
|
9561
|
+
try {
|
|
9562
|
+
config.onComplete?.(toPublicTask(task));
|
|
9563
|
+
} catch {}
|
|
9564
|
+
task.resolve(result);
|
|
9565
|
+
} catch (err2) {
|
|
9566
|
+
if (task.status === "cancelled")
|
|
9567
|
+
return;
|
|
9568
|
+
const error = err2 instanceof Error ? err2 : new Error(String(err2));
|
|
9569
|
+
task.status = "failed";
|
|
9570
|
+
task.error = error;
|
|
9571
|
+
task.completedAt = Date.now();
|
|
9572
|
+
emitProgress(task, { type: "failed", taskId: task.id, error });
|
|
9573
|
+
try {
|
|
9574
|
+
config.onError?.(toPublicTask(task), error);
|
|
9575
|
+
} catch {}
|
|
9576
|
+
task.reject(error);
|
|
9577
|
+
}
|
|
9578
|
+
}
|
|
9579
|
+
return {
|
|
9580
|
+
submit(input, options = {}) {
|
|
9581
|
+
const taskId = options.taskId ?? generateId("task");
|
|
9582
|
+
const abortController = new AbortController;
|
|
9583
|
+
if (options.signal) {
|
|
9584
|
+
options.signal.addEventListener("abort", () => abortController.abort(), { once: true });
|
|
9585
|
+
}
|
|
9586
|
+
let resolvePromise;
|
|
9587
|
+
let rejectPromise;
|
|
9588
|
+
const promise = new Promise((resolve, reject) => {
|
|
9589
|
+
resolvePromise = resolve;
|
|
9590
|
+
rejectPromise = reject;
|
|
9591
|
+
});
|
|
9592
|
+
const task = {
|
|
9593
|
+
id: taskId,
|
|
9594
|
+
agentName: config.agent.name,
|
|
9595
|
+
input,
|
|
9596
|
+
status: "pending",
|
|
9597
|
+
result: null,
|
|
9598
|
+
error: null,
|
|
9599
|
+
createdAt: Date.now(),
|
|
9600
|
+
startedAt: null,
|
|
9601
|
+
completedAt: null,
|
|
9602
|
+
metadata: { ...options.metadata },
|
|
9603
|
+
abortController,
|
|
9604
|
+
promise,
|
|
9605
|
+
resolve: resolvePromise,
|
|
9606
|
+
reject: rejectPromise
|
|
9607
|
+
};
|
|
9608
|
+
tasks.set(taskId, task);
|
|
9609
|
+
executeTask(task);
|
|
9610
|
+
return toPublicTask(task);
|
|
9611
|
+
},
|
|
9612
|
+
getTask(taskId) {
|
|
9613
|
+
const task = tasks.get(taskId);
|
|
9614
|
+
return task ? toPublicTask(task) : null;
|
|
9615
|
+
},
|
|
9616
|
+
listTasks(filter) {
|
|
9617
|
+
const all = [...tasks.values()];
|
|
9618
|
+
const filtered = filter?.status ? all.filter((t) => t.status === filter.status) : all;
|
|
9619
|
+
return filtered.map(toPublicTask);
|
|
9620
|
+
},
|
|
9621
|
+
cancelAll() {
|
|
9622
|
+
for (const task of tasks.values()) {
|
|
9623
|
+
if (task.status === "pending" || task.status === "running") {
|
|
9624
|
+
task.status = "cancelled";
|
|
9625
|
+
task.completedAt = Date.now();
|
|
9626
|
+
task.abortController.abort();
|
|
9627
|
+
emitProgress(task, { type: "cancelled", taskId: task.id });
|
|
9628
|
+
task.reject(new ElsiumError({
|
|
9629
|
+
code: "VALIDATION_ERROR",
|
|
9630
|
+
message: `Task ${task.id} was cancelled`,
|
|
9631
|
+
retryable: false
|
|
9632
|
+
}));
|
|
9633
|
+
}
|
|
9634
|
+
}
|
|
9635
|
+
}
|
|
9636
|
+
};
|
|
9637
|
+
}
|
|
9132
9638
|
// ../rag/src/loaders.ts
|
|
9133
9639
|
function createDocument(content, metadata) {
|
|
9134
9640
|
return {
|
|
@@ -15234,6 +15740,7 @@ export {
|
|
|
15234
15740
|
observe,
|
|
15235
15741
|
mockProvider,
|
|
15236
15742
|
loggingMiddleware,
|
|
15743
|
+
loadThread,
|
|
15237
15744
|
loadFixture,
|
|
15238
15745
|
listProviders,
|
|
15239
15746
|
jsonParseTool,
|
|
@@ -15268,6 +15775,7 @@ export {
|
|
|
15268
15775
|
defineAgent,
|
|
15269
15776
|
currentTimeTool,
|
|
15270
15777
|
createToolkit,
|
|
15778
|
+
createThread,
|
|
15271
15779
|
createStream,
|
|
15272
15780
|
createSqliteMemoryStore,
|
|
15273
15781
|
createSpan,
|
|
@@ -15290,6 +15798,7 @@ export {
|
|
|
15290
15798
|
createMCPServer,
|
|
15291
15799
|
createMCPClient,
|
|
15292
15800
|
createLogger,
|
|
15801
|
+
createInMemoryThreadStore,
|
|
15293
15802
|
createInMemoryStore,
|
|
15294
15803
|
createInMemoryMemoryStore,
|
|
15295
15804
|
createInMemoryCache,
|
|
@@ -15301,8 +15810,10 @@ export {
|
|
|
15301
15810
|
createConfidenceScorer,
|
|
15302
15811
|
createClient,
|
|
15303
15812
|
createBatch,
|
|
15813
|
+
createAsyncAgent,
|
|
15304
15814
|
createApp,
|
|
15305
15815
|
createAnthropicProvider,
|
|
15816
|
+
createAgentStream,
|
|
15306
15817
|
createAgentSecurity,
|
|
15307
15818
|
countTokens,
|
|
15308
15819
|
costTrackingMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elsium-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "ElsiumAI — A high-performance, TypeScript-first AI framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Utrera <ebutrera9103@gmail.com>",
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"build": "bun build ./src/index.ts --outdir ./dist --target node && bun x tsc -p tsconfig.build.json --emitDeclarationOnly"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@elsium-ai/core": "^0.
|
|
29
|
-
"@elsium-ai/gateway": "^0.
|
|
30
|
-
"@elsium-ai/agents": "^0.
|
|
31
|
-
"@elsium-ai/tools": "^0.
|
|
32
|
-
"@elsium-ai/rag": "^0.
|
|
33
|
-
"@elsium-ai/workflows": "^0.
|
|
34
|
-
"@elsium-ai/observe": "^0.
|
|
35
|
-
"@elsium-ai/app": "^0.
|
|
36
|
-
"@elsium-ai/testing": "^0.
|
|
37
|
-
"@elsium-ai/mcp": "^0.
|
|
38
|
-
"@elsium-ai/client": "^0.
|
|
28
|
+
"@elsium-ai/core": "^0.5.0",
|
|
29
|
+
"@elsium-ai/gateway": "^0.5.0",
|
|
30
|
+
"@elsium-ai/agents": "^0.5.0",
|
|
31
|
+
"@elsium-ai/tools": "^0.5.0",
|
|
32
|
+
"@elsium-ai/rag": "^0.5.0",
|
|
33
|
+
"@elsium-ai/workflows": "^0.5.0",
|
|
34
|
+
"@elsium-ai/observe": "^0.5.0",
|
|
35
|
+
"@elsium-ai/app": "^0.5.0",
|
|
36
|
+
"@elsium-ai/testing": "^0.5.0",
|
|
37
|
+
"@elsium-ai/mcp": "^0.5.0",
|
|
38
|
+
"@elsium-ai/client": "^0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"typescript": "^5.7.0"
|