elsium-ai 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +713 -72
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
export { ElsiumError, ok, err, isOk, isErr, unwrap, unwrapOr, tryCatch, tryCatchSync, createStream, ElsiumStream, createLogger, env, envNumber, envBool, generateId, generateTraceId, extractText, sleep, retry, zodToJsonSchema, createRegistry, countTokens, createContextManager, createCircuitBreaker, createDedup, dedupMiddleware, createPolicySet, policyMiddleware, modelAccessPolicy, tokenLimitPolicy, costLimitPolicy, contentPolicy, createShutdownManager, } from '@elsium-ai/core';
|
|
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, MiddlewareContext, MiddlewareNext, StreamMiddleware, StreamMiddlewareNext, Result, Ok, Err, ResilientStreamOptions, StreamTransformer, LogLevel, Logger, LogEntry, LoggerOptions, ErrorCode, ErrorDetails, Registry, ContextStrategy, ContextManagerConfig, ContextManager, CircuitBreakerConfig, CircuitBreaker, CircuitState, DedupConfig, Dedup, PolicyDecision, PolicyResult, PolicyContext, PolicyRule, PolicyConfig, PolicySet, ShutdownConfig, ShutdownManager, } from '@elsium-ai/core';
|
|
14
14
|
export { gateway, registerProviderFactory, registerProvider, getProviderFactory, listProviders, registerProviderMetadata, getProviderMetadata, calculateCost, registerPricing, estimateCost, composeMiddleware, composeStreamMiddleware, loggingMiddleware, costTrackingMiddleware, xrayMiddleware, createAnthropicProvider, createOpenAIProvider, createGoogleProvider, createOpenAICompatibleProvider, createProviderMesh, securityMiddleware, detectPromptInjection, detectJailbreak, redactSecrets, checkBlockedPatterns, classifyContent, cacheMiddleware, createInMemoryCache, outputGuardrailMiddleware, createBatch, createBulkhead, bulkheadMiddleware, } from '@elsium-ai/gateway';
|
|
15
|
-
export type { LLMProvider, ProviderFactory, ProviderMetadata, ModelPricing, ModelTier, Gateway, GatewayConfig, XRayStore, ProviderMeshConfig, ProviderEntry, RoutingStrategy, ProviderMesh, MeshAuditLogger, SecurityMiddlewareConfig, SecurityViolation, SecurityResult, DataClassification, ClassificationResult, OpenAICompatibleConfig, CacheAdapter, CacheStats, CacheMiddlewareConfig, OutputGuardrailConfig, OutputGuardrailRule, OutputViolation, BatchConfig, BatchResult, BatchResultItem, BulkheadConfig, Bulkhead, } from '@elsium-ai/gateway';
|
|
15
|
+
export type { LLMProvider, ProviderFactory, ProviderMetadata, ModelPricing, ModelTier, Gateway, GatewayConfig, ExtractOptions, XRayStore, ProviderMeshConfig, ProviderEntry, RoutingStrategy, ProviderMesh, MeshAuditLogger, SecurityMiddlewareConfig, SecurityViolation, SecurityResult, DataClassification, ClassificationResult, OpenAICompatibleConfig, CacheAdapter, CacheStats, CacheMiddlewareConfig, OutputGuardrailConfig, OutputGuardrailRule, OutputViolation, BatchConfig, BatchResult, BatchResultItem, BulkheadConfig, Bulkhead, } from '@elsium-ai/gateway';
|
|
16
16
|
export { defineAgent, runSequential, runParallel, runSupervisor, createMemory, createSummarizeFn, createSemanticValidator, createAgentSecurity, createConfidenceScorer, executeStateMachine, defineReActAgent, createInMemoryMemoryStore, createSqliteMemoryStore, createSharedMemory, createAgentStream, createThread, loadThread, createInMemoryThreadStore, createAsyncAgent, createApprovalGate, shouldRequireApproval, createChannelGateway, createWebhookChannel, createSessionRouter, createScheduler, parseCronExpression, cronMatchesDate, getNextCronDate, } from '@elsium-ai/agents';
|
|
17
17
|
export type { Agent, AgentDependencies, AgentGenerateResult, AgentConfig, AgentResult, AgentRunOptions, GuardrailConfig, AgentHooks, Memory, MemoryConfig, SummarizeFn, SemanticGuardrailConfig, SemanticCheck, SemanticCheckResult, SemanticValidationResult, SemanticValidator, AgentSecurityConfig, AgentSecurityResult, ConfidenceConfig, ConfidenceResult, StateDefinition, StateHistoryEntry, StateMachineResult, ReActConfig, ReActResult, ReActStep, ReActAgent, MultiAgentConfig, MultiAgentOptions, MemoryStore, SqliteMemoryStoreConfig, SharedMemory, AgentStreamEvent, AgentStream, StreamingAgentDependencies, Thread, ThreadConfig, ThreadStore, ThreadSnapshot, ThreadSummary, AsyncAgent, AsyncAgentConfig, AsyncAgentRunOptions, AgentTask, TaskStatus, TaskProgressEvent, ApprovalRequest, ApprovalDecision, ApprovalCallback, ApprovalGateConfig, ApprovalGate, ChannelAdapter, ChannelGateway, ChannelGatewayConfig, IncomingMessage, OutgoingMessage, ChannelAttachment, WebhookChannelConfig, SessionRouter, SessionRouterConfig, SessionInfo, SessionResolveOptions, Scheduler, SchedulerConfig, ScheduleOptions, ScheduledTask, CronFields, } from '@elsium-ai/agents';
|
|
18
18
|
export { defineTool, createToolkit, httpFetchTool, calculatorTool, jsonParseTool, currentTimeTool, formatToolResult, formatToolResultAsText, createRetrievalTool, } from '@elsium-ai/tools';
|
|
@@ -21,14 +21,14 @@ export { rag, createInMemoryStore, createOpenAIEmbeddings, createMockEmbeddings,
|
|
|
21
21
|
export type { RAGPipeline, RAGPipelineConfig, IngestResult, Document, DocumentMetadata, Chunk, ChunkMetadata, EmbeddedChunk, EmbeddingVector, RetrievalResult, QueryOptions, LoaderType, ChunkingStrategy, ChunkingConfig, EmbeddingConfig, VectorStoreConfig, RetrievalConfig, EmbeddingProvider, VectorStore, VectorStoreFactory, EmbeddingProviderFactory, DocumentLoader, Chunker, PgVectorStoreConfig, QdrantStoreConfig, GoogleEmbeddingsConfig, CohereEmbeddingsConfig, BinaryDocumentLoader, PdfLoaderOptions, BM25Index, HybridSearch, HybridSearchConfig, } from '@elsium-ai/rag';
|
|
22
22
|
export { defineWorkflow, defineParallelWorkflow, defineBranchWorkflow, defineDagWorkflow, defineResumableWorkflow, createInMemoryCheckpointStore, step, } from '@elsium-ai/workflows';
|
|
23
23
|
export type { Workflow, WorkflowConfig, WorkflowResult, WorkflowRunOptions, WorkflowStatus, StepConfig, StepContext, StepResult, StepStatus, RetryConfig, ParallelWorkflowConfig, BranchConfig, DagStepConfig, DagWorkflowConfig, ResumableWorkflow, ResumableWorkflowConfig, ResumableWorkflowRunOptions, WorkflowCheckpoint, CheckpointStore, } from '@elsium-ai/workflows';
|
|
24
|
-
export { observe, createSpan, createMetrics, createCostEngine, registerModelTier, createAuditTrail, auditMiddleware, createProvenanceTracker, createExperiment, createFileExperimentStore, instrumentComplete, instrumentAgent, toOTelSpan, toOTelExportRequest, toTraceparent, parseTraceparent, injectTraceContext, extractTraceContext, createOTLPExporter, } from '@elsium-ai/observe';
|
|
25
|
-
export type { Tracer, TracerConfig, TracerExporter, TracerOutput, CostReport, Span, SpanData, SpanEvent, SpanKind, SpanStatus, SpanHandler, MetricsCollector, MetricEntry, CostEngine, CostEngineConfig, BudgetConfig, LoopDetectionConfig, CostAlert, CostDimension, CostIntelligenceReport, ModelSuggestion, ModelTierEntry, AuditEventType, AuditEvent, AuditStorageAdapter, AuditQueryFilter, AuditIntegrityResult, AuditTrailConfig, AuditBatchConfig, AuditTrail, ProvenanceRecord, ProvenanceTracker, Experiment, ExperimentConfig, ExperimentVariant, ExperimentResults, ExperimentStore, InstrumentableAgent, OTelSpan, OTelSpanKind, OTelStatusCode, OTelAttribute, OTelAttributeValue, OTelEvent, OTelResource, OTelExportRequest, TraceContext, OTLPExporterConfig, } from '@elsium-ai/observe';
|
|
24
|
+
export { observe, createSpan, createMetrics, createCostEngine, registerModelTier, createAuditTrail, auditMiddleware, auditStreamMiddleware, createSinkManager, createWebhookSink, createSplunkSink, createDatadogSink, createProvenanceTracker, createExperiment, createFileExperimentStore, instrumentComplete, instrumentAgent, createStudioExporter, toOTelSpan, toOTelExportRequest, toTraceparent, parseTraceparent, injectTraceContext, extractTraceContext, createOTLPExporter, } from '@elsium-ai/observe';
|
|
25
|
+
export type { Tracer, TracerConfig, TracerExporter, TracerOutput, CostReport, Span, SpanData, SpanEvent, SpanKind, SpanStatus, SpanHandler, MetricsCollector, MetricEntry, CostEngine, CostEngineConfig, BudgetConfig, LoopDetectionConfig, CostAlert, CostDimension, CostIntelligenceReport, ModelSuggestion, ModelTierEntry, AuditEventType, AuditEvent, AuditStorageAdapter, AuditQueryFilter, AuditIntegrityResult, AuditTrailConfig, AuditBatchConfig, AuditTrail, AuditSink, AuditSinkRetryConfig, SinkManagerConfig, SinkManager, WebhookSinkConfig, SplunkSinkConfig, DatadogSinkConfig, ProvenanceRecord, ProvenanceTracker, Experiment, ExperimentConfig, ExperimentVariant, ExperimentResults, ExperimentStore, InstrumentableAgent, StudioExporter, StudioExporterConfig, OTelSpan, OTelSpanKind, OTelStatusCode, OTelAttribute, OTelAttributeValue, OTelEvent, OTelResource, OTelExportRequest, TraceContext, OTLPExporterConfig, } from '@elsium-ai/observe';
|
|
26
26
|
export { createApp, sseHeaders, formatSSE, streamResponse, tenantMiddleware, tenantRateLimitMiddleware, } from '@elsium-ai/app';
|
|
27
27
|
export type { AppConfig, ServerConfig, CorsConfig, AuthConfig, RateLimitConfig, StreamChatEvent, StreamCompleteEvent, TenantMiddlewareConfig, } from '@elsium-ai/app';
|
|
28
28
|
export { createMCPClient, createMCPServer, createMCPHttpHandler } from '@elsium-ai/mcp';
|
|
29
29
|
export type { MCPClient, MCPClientConfig, MCPClientStdioConfig, MCPClientHttpConfig, MCPToolInfo, MCPServer, MCPServerConfig, MCPHttpHandlerConfig, MCPHttpHandler, MCPResourceHandler, MCPPromptHandler, JsonRpcRequest, JsonRpcResponse, MCPTransport, MCPResource, MCPResourceContent, MCPPrompt, MCPPromptArgument, MCPPromptMessage, } from '@elsium-ai/mcp';
|
|
30
30
|
export { createClient } from '@elsium-ai/client';
|
|
31
31
|
export type { ElsiumClient, ClientConfig, } from '@elsium-ai/client';
|
|
32
|
-
export { mockProvider, createFixture, loadFixture, createRecorder, runEvalSuite, formatEvalReport, createSnapshotStore, createPromptRegistry, definePrompt, createRegressionSuite, createReplayRecorder, createReplayPlayer, } from '@elsium-ai/testing';
|
|
33
|
-
export type { MockProviderOptions, MockResponseConfig, MockProvider, EvalSuiteConfig, EvalCase, EvalCriterion, EvalResult, EvalSuiteResult, LLMJudge, SnapshotStore, PromptDefinition, PromptDiff, PromptRegistry, RegressionBaseline, RegressionResult, RegressionDetail, RegressionSuite, ReplayEntry, ReplayRecorder, ReplayPlayer, } from '@elsium-ai/testing';
|
|
32
|
+
export { mockProvider, createFixture, loadFixture, createRecorder, runEvalSuite, formatEvalReport, createSnapshotStore, createPromptRegistry, definePrompt, createRegressionSuite, createReplayRecorder, createReplayPlayer, loadDataset, loadDatasetFromJSON, loadDatasetFromCSV, saveBaseline, loadBaseline, compareResults, formatComparison, } from '@elsium-ai/testing';
|
|
33
|
+
export type { MockProviderOptions, MockResponseConfig, MockProvider, EvalSuiteConfig, EvalCase, EvalCriterion, EvalResult, EvalSuiteResult, LLMJudge, SnapshotStore, PromptDefinition, PromptDiff, PromptRegistry, RegressionBaseline, RegressionResult, RegressionDetail, RegressionSuite, ReplayEntry, ReplayRecorder, ReplayPlayer, EvalDataset, DatasetLoaderOptions, EvalBaseline, EvalComparison, } from '@elsium-ai/testing';
|
|
34
34
|
//# sourceMappingURL=index.d.ts.map
|
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,EACZ,YAAY,EAEZ,YAAY,EAEZ,GAAG,EACH,SAAS,EACT,OAAO,EAEP,UAAU,EACV,eAAe,EACf,WAAW,EACX,KAAK,EACL,KAAK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AAgB,CAAA;AAEvB,YAAY,EACX,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,kBAAkB,GAClB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,6BAA6B,EAC7B,IAAI,GACJ,MAAM,sBAAsB,CAAA;AAE7B,YAAY,EACX,QAAQ,EACR,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,2BAA2B,EAC3B,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EACN,OAAO,EACP,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EAEjB,gBAAgB,EAChB,eAAe,
|
|
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,EACZ,YAAY,EAEZ,YAAY,EAEZ,GAAG,EACH,SA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AAmB,EACnB,WAAW,EACX,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAEhB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,YAAY,EACX,YAAY,EACZ,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACN,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAElB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,GAChB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,EACd,YAAY,EAEZ,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,cAAc,GACd,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2856,6 +2856,38 @@ function gateway(config) {
|
|
|
2856
2856
|
});
|
|
2857
2857
|
}
|
|
2858
2858
|
return { data: result.data, response };
|
|
2859
|
+
},
|
|
2860
|
+
async extract(schema, input, options) {
|
|
2861
|
+
const maxRetries = options?.maxRetries ?? 3;
|
|
2862
|
+
const messages = [{ role: "user", content: input }];
|
|
2863
|
+
let lastError;
|
|
2864
|
+
for (let attempt = 0;attempt <= maxRetries; attempt++) {
|
|
2865
|
+
try {
|
|
2866
|
+
const result = await this.generate({
|
|
2867
|
+
messages: [...messages],
|
|
2868
|
+
schema,
|
|
2869
|
+
model: options?.model,
|
|
2870
|
+
system: options?.system,
|
|
2871
|
+
temperature: options?.temperature
|
|
2872
|
+
});
|
|
2873
|
+
return result.data;
|
|
2874
|
+
} catch (e) {
|
|
2875
|
+
if (e instanceof ElsiumError && e.code === "VALIDATION_ERROR") {
|
|
2876
|
+
lastError = e;
|
|
2877
|
+
messages.push({
|
|
2878
|
+
role: "assistant",
|
|
2879
|
+
content: "Invalid output"
|
|
2880
|
+
});
|
|
2881
|
+
messages.push({
|
|
2882
|
+
role: "user",
|
|
2883
|
+
content: `The previous response failed validation: ${e.message}. Please try again and return valid JSON matching the schema.`
|
|
2884
|
+
});
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
throw e;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
throw lastError;
|
|
2859
2891
|
}
|
|
2860
2892
|
};
|
|
2861
2893
|
}
|
|
@@ -3804,10 +3836,10 @@ function createProviderMesh(config) {
|
|
|
3804
3836
|
};
|
|
3805
3837
|
}());
|
|
3806
3838
|
}
|
|
3807
|
-
function logStreamFailover(provider, error) {
|
|
3839
|
+
function logStreamFailover(provider, toProvider, error) {
|
|
3808
3840
|
audit?.log("provider_failover", {
|
|
3809
3841
|
fromProvider: provider,
|
|
3810
|
-
toProvider
|
|
3842
|
+
toProvider,
|
|
3811
3843
|
strategy: config.strategy,
|
|
3812
3844
|
reason: error?.message
|
|
3813
3845
|
});
|
|
@@ -3830,25 +3862,33 @@ function createProviderMesh(config) {
|
|
|
3830
3862
|
}
|
|
3831
3863
|
return { success: true };
|
|
3832
3864
|
}
|
|
3865
|
+
async function attemptStreamProvider(entry, nextProvider, request, emit) {
|
|
3866
|
+
try {
|
|
3867
|
+
const result = await tryStreamProvider(entry, request, emit);
|
|
3868
|
+
if (result.success)
|
|
3869
|
+
return { success: true };
|
|
3870
|
+
logStreamFailover(entry.name, nextProvider, result.error);
|
|
3871
|
+
return { success: false, error: result.error };
|
|
3872
|
+
} catch (err2) {
|
|
3873
|
+
const error = toError2(err2);
|
|
3874
|
+
logStreamFailover(entry.name, nextProvider, error);
|
|
3875
|
+
return { success: false, error };
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3833
3878
|
async function runStreamFallbackLoop(available, request, emit) {
|
|
3834
3879
|
let lastError = null;
|
|
3835
3880
|
let failedProvider = null;
|
|
3836
|
-
for (
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
lastError = result.error ?? null;
|
|
3845
|
-
failedProvider = entry.name;
|
|
3846
|
-
logStreamFailover(entry.name, result.error);
|
|
3847
|
-
} catch (err2) {
|
|
3848
|
-
failedProvider = entry.name;
|
|
3849
|
-
lastError = toError2(err2);
|
|
3850
|
-
logStreamFailover(entry.name, lastError);
|
|
3881
|
+
for (let i = 0;i < available.length; i++) {
|
|
3882
|
+
const entry = available[i];
|
|
3883
|
+
const nextProvider = i + 1 < available.length ? available[i + 1].name : "none";
|
|
3884
|
+
const attempt = await attemptStreamProvider(entry, nextProvider, request, emit);
|
|
3885
|
+
if (attempt.success) {
|
|
3886
|
+
if (failedProvider)
|
|
3887
|
+
logFailover(failedProvider, entry.name, lastError?.message);
|
|
3888
|
+
return;
|
|
3851
3889
|
}
|
|
3890
|
+
lastError = attempt.error ?? null;
|
|
3891
|
+
failedProvider = entry.name;
|
|
3852
3892
|
}
|
|
3853
3893
|
emit({
|
|
3854
3894
|
type: "error",
|
|
@@ -13150,6 +13190,110 @@ function createMetrics(options) {
|
|
|
13150
13190
|
}
|
|
13151
13191
|
// ../observe/src/audit.ts
|
|
13152
13192
|
import { createHash as createHash3 } from "node:crypto";
|
|
13193
|
+
|
|
13194
|
+
// ../observe/src/audit-sink.ts
|
|
13195
|
+
var log10 = createLogger();
|
|
13196
|
+
function getRetryDelay2(attempt, baseDelayMs, maxDelayMs) {
|
|
13197
|
+
const delay = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);
|
|
13198
|
+
return delay * (0.5 + Math.random() * 0.5);
|
|
13199
|
+
}
|
|
13200
|
+
async function sendWithRetry(sink, events, retryConfig) {
|
|
13201
|
+
let lastError;
|
|
13202
|
+
for (let attempt = 0;attempt <= retryConfig.maxRetries; attempt++) {
|
|
13203
|
+
try {
|
|
13204
|
+
await sink.send(events);
|
|
13205
|
+
return;
|
|
13206
|
+
} catch (error) {
|
|
13207
|
+
lastError = error;
|
|
13208
|
+
if (attempt < retryConfig.maxRetries) {
|
|
13209
|
+
const delay = getRetryDelay2(attempt, retryConfig.baseDelayMs, retryConfig.maxDelayMs);
|
|
13210
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
13211
|
+
}
|
|
13212
|
+
}
|
|
13213
|
+
}
|
|
13214
|
+
throw lastError;
|
|
13215
|
+
}
|
|
13216
|
+
async function deliverToSink(sink, events, retryConfig, deadLetterSink, onError) {
|
|
13217
|
+
const filtered = sink.filter ? events.filter(sink.filter) : events;
|
|
13218
|
+
if (filtered.length === 0)
|
|
13219
|
+
return;
|
|
13220
|
+
try {
|
|
13221
|
+
await sendWithRetry(sink, filtered, retryConfig);
|
|
13222
|
+
} catch (error) {
|
|
13223
|
+
log10.error("Audit sink delivery failed", { sink: sink.name });
|
|
13224
|
+
onError?.(sink.name, error);
|
|
13225
|
+
if (!deadLetterSink)
|
|
13226
|
+
return;
|
|
13227
|
+
try {
|
|
13228
|
+
await deadLetterSink.send(filtered);
|
|
13229
|
+
} catch (dlqError) {
|
|
13230
|
+
log10.error("Dead letter sink delivery failed", { sink: deadLetterSink.name });
|
|
13231
|
+
onError?.(deadLetterSink.name, dlqError);
|
|
13232
|
+
}
|
|
13233
|
+
}
|
|
13234
|
+
}
|
|
13235
|
+
function createSinkManager(config) {
|
|
13236
|
+
const { sinks, onError, deadLetterSink } = config;
|
|
13237
|
+
const batchSize = config.batch?.size ?? 50;
|
|
13238
|
+
const batchIntervalMs = config.batch?.intervalMs ?? 5000;
|
|
13239
|
+
const maxBufferSize = config.maxBufferSize ?? 1e4;
|
|
13240
|
+
const retryConfig = {
|
|
13241
|
+
maxRetries: config.retry?.maxRetries ?? 3,
|
|
13242
|
+
baseDelayMs: config.retry?.baseDelayMs ?? 1000,
|
|
13243
|
+
maxDelayMs: config.retry?.maxDelayMs ?? 30000
|
|
13244
|
+
};
|
|
13245
|
+
const buffer = [];
|
|
13246
|
+
const inFlight = new Set;
|
|
13247
|
+
let flushTimer = null;
|
|
13248
|
+
function dispatchBatch(batch) {
|
|
13249
|
+
if (batch.length === 0 || sinks.length === 0)
|
|
13250
|
+
return;
|
|
13251
|
+
const promises = sinks.map((sink) => deliverToSink(sink, batch, retryConfig, deadLetterSink, onError));
|
|
13252
|
+
const combined = Promise.allSettled(promises).then(() => {
|
|
13253
|
+
inFlight.delete(combined);
|
|
13254
|
+
});
|
|
13255
|
+
inFlight.add(combined);
|
|
13256
|
+
}
|
|
13257
|
+
function drainBuffer() {
|
|
13258
|
+
while (buffer.length > 0) {
|
|
13259
|
+
const batch = buffer.splice(0, batchSize);
|
|
13260
|
+
dispatchBatch(batch);
|
|
13261
|
+
}
|
|
13262
|
+
}
|
|
13263
|
+
flushTimer = setInterval(() => {
|
|
13264
|
+
if (buffer.length > 0)
|
|
13265
|
+
drainBuffer();
|
|
13266
|
+
}, batchIntervalMs);
|
|
13267
|
+
if (typeof flushTimer === "object" && "unref" in flushTimer) {
|
|
13268
|
+
flushTimer.unref();
|
|
13269
|
+
}
|
|
13270
|
+
return {
|
|
13271
|
+
dispatch(event) {
|
|
13272
|
+
if (buffer.length >= maxBufferSize) {
|
|
13273
|
+
buffer.shift();
|
|
13274
|
+
log10.warn("Audit sink buffer full, dropping oldest event");
|
|
13275
|
+
}
|
|
13276
|
+
buffer.push(event);
|
|
13277
|
+
if (buffer.length >= batchSize)
|
|
13278
|
+
drainBuffer();
|
|
13279
|
+
},
|
|
13280
|
+
async flush() {
|
|
13281
|
+
drainBuffer();
|
|
13282
|
+
await Promise.allSettled([...inFlight]);
|
|
13283
|
+
},
|
|
13284
|
+
async shutdown() {
|
|
13285
|
+
if (flushTimer) {
|
|
13286
|
+
clearInterval(flushTimer);
|
|
13287
|
+
flushTimer = null;
|
|
13288
|
+
}
|
|
13289
|
+
drainBuffer();
|
|
13290
|
+
await Promise.allSettled([...inFlight]);
|
|
13291
|
+
await Promise.allSettled(sinks.map((sink) => sink.shutdown?.()));
|
|
13292
|
+
}
|
|
13293
|
+
};
|
|
13294
|
+
}
|
|
13295
|
+
|
|
13296
|
+
// ../observe/src/audit.ts
|
|
13153
13297
|
function computeEventHash(event, previousHash) {
|
|
13154
13298
|
const content = JSON.stringify({
|
|
13155
13299
|
id: event.id,
|
|
@@ -13258,16 +13402,34 @@ class InMemoryAuditStorage {
|
|
|
13258
13402
|
return last ? last.hash : ZERO_HASH;
|
|
13259
13403
|
}
|
|
13260
13404
|
}
|
|
13405
|
+
function resolveStorage(config) {
|
|
13406
|
+
if (config?.storage && typeof config.storage !== "string")
|
|
13407
|
+
return config.storage;
|
|
13408
|
+
return new InMemoryAuditStorage(config?.maxEvents);
|
|
13409
|
+
}
|
|
13410
|
+
function resolveSinkManager(config) {
|
|
13411
|
+
if (!config?.sinks)
|
|
13412
|
+
return null;
|
|
13413
|
+
const sinkConfig = Array.isArray(config.sinks) ? { sinks: config.sinks } : config.sinks;
|
|
13414
|
+
return createSinkManager(sinkConfig);
|
|
13415
|
+
}
|
|
13416
|
+
function resolveLastHash(storage) {
|
|
13417
|
+
if (!storage.getLastHash)
|
|
13418
|
+
return ZERO_HASH;
|
|
13419
|
+
return storage.getLastHash();
|
|
13420
|
+
}
|
|
13261
13421
|
function createAuditTrail(config) {
|
|
13262
13422
|
const useHashChain = config?.hashChain !== false;
|
|
13263
|
-
const storage =
|
|
13423
|
+
const storage = resolveStorage(config);
|
|
13424
|
+
const sinkManager = resolveSinkManager(config);
|
|
13425
|
+
const globalContext = config?.context;
|
|
13264
13426
|
let sequenceId = 0;
|
|
13265
13427
|
let idCounter = 0;
|
|
13266
13428
|
let previousHash = ZERO_HASH;
|
|
13267
13429
|
let isReady = true;
|
|
13268
13430
|
let readyPromise = Promise.resolve();
|
|
13269
|
-
if (useHashChain
|
|
13270
|
-
const lastHash = storage
|
|
13431
|
+
if (useHashChain) {
|
|
13432
|
+
const lastHash = resolveLastHash(storage);
|
|
13271
13433
|
if (typeof lastHash === "string") {
|
|
13272
13434
|
previousHash = lastHash;
|
|
13273
13435
|
} else {
|
|
@@ -13285,10 +13447,11 @@ function createAuditTrail(config) {
|
|
|
13285
13447
|
const isBatched = !!batchConfig;
|
|
13286
13448
|
const pendingBuffer = [];
|
|
13287
13449
|
let flushTimer = null;
|
|
13288
|
-
|
|
13450
|
+
let flushPromise = Promise.resolve();
|
|
13289
13451
|
function buildAndAppend(entry) {
|
|
13290
13452
|
sequenceId++;
|
|
13291
13453
|
idCounter++;
|
|
13454
|
+
const data = globalContext ? { ...globalContext, ...entry.data } : entry.data;
|
|
13292
13455
|
const event = {
|
|
13293
13456
|
id: `audit_${idCounter.toString(36)}_${entry.timestamp.toString(36)}`,
|
|
13294
13457
|
sequenceId,
|
|
@@ -13296,7 +13459,7 @@ function createAuditTrail(config) {
|
|
|
13296
13459
|
timestamp: entry.timestamp,
|
|
13297
13460
|
actor: entry.actor,
|
|
13298
13461
|
traceId: entry.traceId,
|
|
13299
|
-
data
|
|
13462
|
+
data,
|
|
13300
13463
|
previousHash: useHashChain ? previousHash : ZERO_HASH
|
|
13301
13464
|
};
|
|
13302
13465
|
const hash = useHashChain ? computeEventHash(event, event.previousHash) : createHash3("sha256").update(JSON.stringify(event)).digest("hex");
|
|
@@ -13305,9 +13468,10 @@ function createAuditTrail(config) {
|
|
|
13305
13468
|
previousHash = hash;
|
|
13306
13469
|
}
|
|
13307
13470
|
const result = storage.append(finalEvent);
|
|
13308
|
-
if (result && typeof result.
|
|
13309
|
-
result.catch((err2) => config?.onError?.(err2));
|
|
13471
|
+
if (result && typeof result.then === "function") {
|
|
13472
|
+
flushPromise = flushPromise.then(() => result).catch((err2) => config?.onError?.(err2));
|
|
13310
13473
|
}
|
|
13474
|
+
sinkManager?.dispatch(finalEvent);
|
|
13311
13475
|
}
|
|
13312
13476
|
function drainBuffer() {
|
|
13313
13477
|
let entry = pendingBuffer.shift();
|
|
@@ -13356,13 +13520,16 @@ function createAuditTrail(config) {
|
|
|
13356
13520
|
await readyPromise;
|
|
13357
13521
|
drainBuffer();
|
|
13358
13522
|
await flushPromise;
|
|
13523
|
+
await sinkManager?.flush();
|
|
13359
13524
|
},
|
|
13360
|
-
dispose() {
|
|
13525
|
+
async dispose() {
|
|
13361
13526
|
if (flushTimer) {
|
|
13362
13527
|
clearInterval(flushTimer);
|
|
13363
13528
|
flushTimer = null;
|
|
13364
13529
|
}
|
|
13365
13530
|
drainBuffer();
|
|
13531
|
+
await flushPromise;
|
|
13532
|
+
await sinkManager?.shutdown();
|
|
13366
13533
|
},
|
|
13367
13534
|
async query(filter) {
|
|
13368
13535
|
if (isBatched)
|
|
@@ -13413,6 +13580,203 @@ function auditMiddleware(auditTrail) {
|
|
|
13413
13580
|
}
|
|
13414
13581
|
};
|
|
13415
13582
|
}
|
|
13583
|
+
function emitStreamAudit(auditTrail, ctx, state, latencyMs) {
|
|
13584
|
+
if (state.hasError && !state.hasUsage) {
|
|
13585
|
+
auditTrail.log("llm_call", {
|
|
13586
|
+
provider: ctx.provider,
|
|
13587
|
+
model: ctx.model,
|
|
13588
|
+
error: state.errorMessage,
|
|
13589
|
+
latencyMs,
|
|
13590
|
+
success: false,
|
|
13591
|
+
streaming: true
|
|
13592
|
+
}, { traceId: ctx.traceId });
|
|
13593
|
+
} else if (state.hasUsage) {
|
|
13594
|
+
auditTrail.log("llm_call", {
|
|
13595
|
+
provider: ctx.provider,
|
|
13596
|
+
model: ctx.model,
|
|
13597
|
+
inputTokens: state.inputTokens,
|
|
13598
|
+
outputTokens: state.outputTokens,
|
|
13599
|
+
totalTokens: state.totalTokens,
|
|
13600
|
+
latencyMs,
|
|
13601
|
+
stopReason: state.stopReason,
|
|
13602
|
+
streaming: true
|
|
13603
|
+
}, { traceId: ctx.traceId });
|
|
13604
|
+
}
|
|
13605
|
+
}
|
|
13606
|
+
function auditStreamMiddleware(auditTrail) {
|
|
13607
|
+
return (ctx, source, next) => {
|
|
13608
|
+
const startTime = performance.now();
|
|
13609
|
+
const processed = next(ctx, source);
|
|
13610
|
+
return async function* () {
|
|
13611
|
+
const state = {
|
|
13612
|
+
inputTokens: 0,
|
|
13613
|
+
outputTokens: 0,
|
|
13614
|
+
totalTokens: 0,
|
|
13615
|
+
hasUsage: false,
|
|
13616
|
+
hasError: false
|
|
13617
|
+
};
|
|
13618
|
+
try {
|
|
13619
|
+
for await (const event of processed) {
|
|
13620
|
+
if (event.type === "message_end") {
|
|
13621
|
+
state.inputTokens = event.usage.inputTokens;
|
|
13622
|
+
state.outputTokens = event.usage.outputTokens;
|
|
13623
|
+
state.totalTokens = event.usage.totalTokens;
|
|
13624
|
+
state.stopReason = event.stopReason;
|
|
13625
|
+
state.hasUsage = true;
|
|
13626
|
+
}
|
|
13627
|
+
if (event.type === "error") {
|
|
13628
|
+
state.hasError = true;
|
|
13629
|
+
state.errorMessage = event.error.message;
|
|
13630
|
+
}
|
|
13631
|
+
yield event;
|
|
13632
|
+
}
|
|
13633
|
+
} finally {
|
|
13634
|
+
const latencyMs = Math.round(performance.now() - startTime);
|
|
13635
|
+
emitStreamAudit(auditTrail, ctx, state, latencyMs);
|
|
13636
|
+
}
|
|
13637
|
+
}();
|
|
13638
|
+
};
|
|
13639
|
+
}
|
|
13640
|
+
// ../observe/src/audit-sink-webhook.ts
|
|
13641
|
+
function createWebhookSink(config) {
|
|
13642
|
+
const { url, headers = {}, method = "POST", timeoutMs = 1e4 } = config;
|
|
13643
|
+
return {
|
|
13644
|
+
name: "webhook",
|
|
13645
|
+
async send(events) {
|
|
13646
|
+
const controller = new AbortController;
|
|
13647
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13648
|
+
try {
|
|
13649
|
+
const response = await fetch(url, {
|
|
13650
|
+
method,
|
|
13651
|
+
headers: {
|
|
13652
|
+
"Content-Type": "application/json",
|
|
13653
|
+
...headers
|
|
13654
|
+
},
|
|
13655
|
+
body: JSON.stringify({ events }),
|
|
13656
|
+
signal: controller.signal
|
|
13657
|
+
});
|
|
13658
|
+
if (!response.ok) {
|
|
13659
|
+
throw new Error(`Webhook responded with ${response.status} ${response.statusText}`);
|
|
13660
|
+
}
|
|
13661
|
+
} catch (error) {
|
|
13662
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13663
|
+
throw new Error(`Webhook request timed out after ${timeoutMs}ms`);
|
|
13664
|
+
}
|
|
13665
|
+
throw error;
|
|
13666
|
+
} finally {
|
|
13667
|
+
clearTimeout(timeout);
|
|
13668
|
+
}
|
|
13669
|
+
}
|
|
13670
|
+
};
|
|
13671
|
+
}
|
|
13672
|
+
// ../observe/src/audit-sink-splunk.ts
|
|
13673
|
+
function toSplunkEvent(event, index, source, sourcetype) {
|
|
13674
|
+
return JSON.stringify({
|
|
13675
|
+
time: event.timestamp / 1000,
|
|
13676
|
+
source: source ?? "elsium-ai",
|
|
13677
|
+
sourcetype: sourcetype ?? "elsium:audit",
|
|
13678
|
+
...index && { index },
|
|
13679
|
+
event
|
|
13680
|
+
});
|
|
13681
|
+
}
|
|
13682
|
+
function createSplunkSink(config) {
|
|
13683
|
+
const { url, token, index, source, sourcetype, timeoutMs = 1e4 } = config;
|
|
13684
|
+
return {
|
|
13685
|
+
name: "splunk",
|
|
13686
|
+
async send(events) {
|
|
13687
|
+
const body = events.map((e) => toSplunkEvent(e, index, source, sourcetype)).join(`
|
|
13688
|
+
`);
|
|
13689
|
+
const controller = new AbortController;
|
|
13690
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13691
|
+
try {
|
|
13692
|
+
const response = await fetch(url, {
|
|
13693
|
+
method: "POST",
|
|
13694
|
+
headers: {
|
|
13695
|
+
Authorization: `Splunk ${token}`,
|
|
13696
|
+
"Content-Type": "application/json"
|
|
13697
|
+
},
|
|
13698
|
+
body,
|
|
13699
|
+
signal: controller.signal
|
|
13700
|
+
});
|
|
13701
|
+
if (!response.ok) {
|
|
13702
|
+
throw new Error(`Splunk HEC responded with ${response.status} ${response.statusText}`);
|
|
13703
|
+
}
|
|
13704
|
+
} catch (error) {
|
|
13705
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13706
|
+
throw new Error(`Splunk HEC request timed out after ${timeoutMs}ms`);
|
|
13707
|
+
}
|
|
13708
|
+
throw error;
|
|
13709
|
+
} finally {
|
|
13710
|
+
clearTimeout(timeout);
|
|
13711
|
+
}
|
|
13712
|
+
}
|
|
13713
|
+
};
|
|
13714
|
+
}
|
|
13715
|
+
// ../observe/src/audit-sink-datadog.ts
|
|
13716
|
+
function formatTags(tags) {
|
|
13717
|
+
return Object.entries(tags).map(([k, v]) => `${k}:${v}`).join(",");
|
|
13718
|
+
}
|
|
13719
|
+
function toDatadogLog(event, service, source, tags) {
|
|
13720
|
+
return {
|
|
13721
|
+
ddsource: source,
|
|
13722
|
+
ddtags: tags ? formatTags(tags) : undefined,
|
|
13723
|
+
service,
|
|
13724
|
+
hostname: "elsium-ai",
|
|
13725
|
+
message: `[${event.type}] ${JSON.stringify(event.data)}`,
|
|
13726
|
+
status: event.type === "security_violation" ? "error" : "info",
|
|
13727
|
+
timestamp: event.timestamp,
|
|
13728
|
+
audit: {
|
|
13729
|
+
id: event.id,
|
|
13730
|
+
sequenceId: event.sequenceId,
|
|
13731
|
+
type: event.type,
|
|
13732
|
+
actor: event.actor,
|
|
13733
|
+
traceId: event.traceId,
|
|
13734
|
+
data: event.data,
|
|
13735
|
+
hash: event.hash,
|
|
13736
|
+
previousHash: event.previousHash
|
|
13737
|
+
}
|
|
13738
|
+
};
|
|
13739
|
+
}
|
|
13740
|
+
function createDatadogSink(config) {
|
|
13741
|
+
const {
|
|
13742
|
+
apiKey,
|
|
13743
|
+
site = "datadoghq.com",
|
|
13744
|
+
service = "elsium-ai",
|
|
13745
|
+
source = "elsium-ai-audit",
|
|
13746
|
+
tags,
|
|
13747
|
+
timeoutMs = 1e4
|
|
13748
|
+
} = config;
|
|
13749
|
+
const endpoint = `https://http-intake.logs.${site}/api/v2/logs`;
|
|
13750
|
+
return {
|
|
13751
|
+
name: "datadog",
|
|
13752
|
+
async send(events) {
|
|
13753
|
+
const body = events.map((e) => toDatadogLog(e, service, source, tags));
|
|
13754
|
+
const controller = new AbortController;
|
|
13755
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13756
|
+
try {
|
|
13757
|
+
const response = await fetch(endpoint, {
|
|
13758
|
+
method: "POST",
|
|
13759
|
+
headers: {
|
|
13760
|
+
"DD-API-KEY": apiKey,
|
|
13761
|
+
"Content-Type": "application/json"
|
|
13762
|
+
},
|
|
13763
|
+
body: JSON.stringify(body),
|
|
13764
|
+
signal: controller.signal
|
|
13765
|
+
});
|
|
13766
|
+
if (!response.ok) {
|
|
13767
|
+
throw new Error(`Datadog Log Intake responded with ${response.status} ${response.statusText}`);
|
|
13768
|
+
}
|
|
13769
|
+
} catch (error) {
|
|
13770
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13771
|
+
throw new Error(`Datadog request timed out after ${timeoutMs}ms`);
|
|
13772
|
+
}
|
|
13773
|
+
throw error;
|
|
13774
|
+
} finally {
|
|
13775
|
+
clearTimeout(timeout);
|
|
13776
|
+
}
|
|
13777
|
+
}
|
|
13778
|
+
};
|
|
13779
|
+
}
|
|
13416
13780
|
// ../observe/src/provenance.ts
|
|
13417
13781
|
import { createHash as createHash4 } from "node:crypto";
|
|
13418
13782
|
function sha256(input) {
|
|
@@ -13474,7 +13838,7 @@ function createProvenanceTracker(options) {
|
|
|
13474
13838
|
import { createHash as createHash5 } from "node:crypto";
|
|
13475
13839
|
import { existsSync, mkdirSync, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
13476
13840
|
import { join } from "node:path";
|
|
13477
|
-
var
|
|
13841
|
+
var log11 = createLogger();
|
|
13478
13842
|
function createFileExperimentStore(dir) {
|
|
13479
13843
|
return {
|
|
13480
13844
|
save(name, data) {
|
|
@@ -13485,7 +13849,7 @@ function createFileExperimentStore(dir) {
|
|
|
13485
13849
|
const filePath = join(dir, `${name}.json`);
|
|
13486
13850
|
writeFileSync2(filePath, JSON.stringify(data, null, 2));
|
|
13487
13851
|
} catch (err2) {
|
|
13488
|
-
|
|
13852
|
+
log11.error("Failed to save experiment", {
|
|
13489
13853
|
name,
|
|
13490
13854
|
error: err2 instanceof Error ? err2.message : String(err2)
|
|
13491
13855
|
});
|
|
@@ -13516,7 +13880,7 @@ function loadFromStore(store, name, stats) {
|
|
|
13516
13880
|
stats[vName].metrics[key] = { sum: m.sum, count: m.count };
|
|
13517
13881
|
}
|
|
13518
13882
|
}
|
|
13519
|
-
|
|
13883
|
+
log11.debug("Loaded experiment state", { name, totalAssignments: saved.totalAssignments });
|
|
13520
13884
|
}
|
|
13521
13885
|
function recordMetrics(s, metrics) {
|
|
13522
13886
|
for (const [key, value] of Object.entries(metrics)) {
|
|
@@ -13584,7 +13948,7 @@ function createExperiment(config) {
|
|
|
13584
13948
|
const s = stats[variant.name];
|
|
13585
13949
|
if (s)
|
|
13586
13950
|
s.assignments++;
|
|
13587
|
-
|
|
13951
|
+
log11.debug("Experiment assignment", {
|
|
13588
13952
|
experiment: name,
|
|
13589
13953
|
variant: variant.name,
|
|
13590
13954
|
userId
|
|
@@ -13652,8 +14016,72 @@ function instrumentAgent(agent, tracer) {
|
|
|
13652
14016
|
};
|
|
13653
14017
|
return instrumented;
|
|
13654
14018
|
}
|
|
14019
|
+
// ../observe/src/studio-exporter.ts
|
|
14020
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
14021
|
+
import { join as join2 } from "node:path";
|
|
14022
|
+
var log12 = createLogger();
|
|
14023
|
+
function ensureDir(dirPath) {
|
|
14024
|
+
if (!existsSync2(dirPath)) {
|
|
14025
|
+
mkdirSync2(dirPath, { recursive: true });
|
|
14026
|
+
}
|
|
14027
|
+
}
|
|
14028
|
+
function safeWriteJSON(filePath, data) {
|
|
14029
|
+
try {
|
|
14030
|
+
writeFileSync3(filePath, JSON.stringify(data, null, 2));
|
|
14031
|
+
} catch (err2) {
|
|
14032
|
+
log12.error("Studio exporter write failed", {
|
|
14033
|
+
file: filePath,
|
|
14034
|
+
error: err2 instanceof Error ? err2.message : String(err2)
|
|
14035
|
+
});
|
|
14036
|
+
}
|
|
14037
|
+
}
|
|
14038
|
+
function safeReadJSON(filePath, fallback) {
|
|
14039
|
+
try {
|
|
14040
|
+
if (!existsSync2(filePath))
|
|
14041
|
+
return fallback;
|
|
14042
|
+
return JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
14043
|
+
} catch {
|
|
14044
|
+
return fallback;
|
|
14045
|
+
}
|
|
14046
|
+
}
|
|
14047
|
+
function createStudioExporter(config) {
|
|
14048
|
+
const baseDir = config?.dir ?? ".elsium";
|
|
14049
|
+
const tracesDir = join2(baseDir, "traces");
|
|
14050
|
+
const xrayFile = join2(baseDir, "xray-history.json");
|
|
14051
|
+
const costFile = join2(baseDir, "cost-report.json");
|
|
14052
|
+
ensureDir(tracesDir);
|
|
14053
|
+
return {
|
|
14054
|
+
name: "studio",
|
|
14055
|
+
export(spans) {
|
|
14056
|
+
for (const span of spans) {
|
|
14057
|
+
if (!span.traceId)
|
|
14058
|
+
continue;
|
|
14059
|
+
const filePath = join2(tracesDir, `${span.traceId}.json`);
|
|
14060
|
+
safeWriteJSON(filePath, span);
|
|
14061
|
+
}
|
|
14062
|
+
},
|
|
14063
|
+
writeXRayEntry(entry) {
|
|
14064
|
+
const history = safeReadJSON(xrayFile, []);
|
|
14065
|
+
history.unshift(entry);
|
|
14066
|
+
if (history.length > 500)
|
|
14067
|
+
history.length = 500;
|
|
14068
|
+
safeWriteJSON(xrayFile, history);
|
|
14069
|
+
},
|
|
14070
|
+
writeCostReport(report) {
|
|
14071
|
+
safeWriteJSON(costFile, {
|
|
14072
|
+
totalRequests: report.callCount,
|
|
14073
|
+
totalTokens: report.totalTokens,
|
|
14074
|
+
totalCost: report.totalCost,
|
|
14075
|
+
byModel: Object.fromEntries(Object.entries(report.byModel).map(([model, data]) => [
|
|
14076
|
+
model,
|
|
14077
|
+
{ requests: data.calls, tokens: data.tokens, cost: data.cost }
|
|
14078
|
+
]))
|
|
14079
|
+
});
|
|
14080
|
+
}
|
|
14081
|
+
};
|
|
14082
|
+
}
|
|
13655
14083
|
// ../observe/src/otel.ts
|
|
13656
|
-
var
|
|
14084
|
+
var log13 = createLogger();
|
|
13657
14085
|
var SPAN_KIND_MAP = {
|
|
13658
14086
|
llm: 3,
|
|
13659
14087
|
tool: 1,
|
|
@@ -13794,10 +14222,10 @@ function createOTLPExporter(config) {
|
|
|
13794
14222
|
body: JSON.stringify(payload)
|
|
13795
14223
|
});
|
|
13796
14224
|
if (!response.ok) {
|
|
13797
|
-
|
|
14225
|
+
log13.error(`OTLP export failed: ${response.status} ${response.statusText}`);
|
|
13798
14226
|
}
|
|
13799
14227
|
} catch (err2) {
|
|
13800
|
-
|
|
14228
|
+
log13.error("OTLP export error", { error: err2 instanceof Error ? err2.message : String(err2) });
|
|
13801
14229
|
}
|
|
13802
14230
|
}
|
|
13803
14231
|
function startAutoFlush() {
|
|
@@ -14367,7 +14795,7 @@ var serve = (options, listeningListener) => {
|
|
|
14367
14795
|
return server;
|
|
14368
14796
|
};
|
|
14369
14797
|
|
|
14370
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14798
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/compose.js
|
|
14371
14799
|
var compose = (middleware, onError, onNotFound) => {
|
|
14372
14800
|
return (context, next) => {
|
|
14373
14801
|
let index = -1;
|
|
@@ -14411,10 +14839,10 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
14411
14839
|
};
|
|
14412
14840
|
};
|
|
14413
14841
|
|
|
14414
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14842
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request/constants.js
|
|
14415
14843
|
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
14416
14844
|
|
|
14417
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14845
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/body.js
|
|
14418
14846
|
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
14419
14847
|
const { all = false, dot = false } = options;
|
|
14420
14848
|
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
@@ -14468,6 +14896,9 @@ var handleParsingAllValues = (form, key, value) => {
|
|
|
14468
14896
|
}
|
|
14469
14897
|
};
|
|
14470
14898
|
var handleParsingNestedValues = (form, key, value) => {
|
|
14899
|
+
if (/(?:^|\.)__proto__\./.test(key)) {
|
|
14900
|
+
return;
|
|
14901
|
+
}
|
|
14471
14902
|
let nestedForm = form;
|
|
14472
14903
|
const keys = key.split(".");
|
|
14473
14904
|
keys.forEach((key2, index) => {
|
|
@@ -14482,7 +14913,7 @@ var handleParsingNestedValues = (form, key, value) => {
|
|
|
14482
14913
|
});
|
|
14483
14914
|
};
|
|
14484
14915
|
|
|
14485
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14916
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/url.js
|
|
14486
14917
|
var splitPath = (path) => {
|
|
14487
14918
|
const paths = path.split("/");
|
|
14488
14919
|
if (paths[0] === "") {
|
|
@@ -14682,7 +15113,7 @@ var getQueryParams = (url, key) => {
|
|
|
14682
15113
|
};
|
|
14683
15114
|
var decodeURIComponent_ = decodeURIComponent;
|
|
14684
15115
|
|
|
14685
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15116
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request.js
|
|
14686
15117
|
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
14687
15118
|
var HonoRequest = class {
|
|
14688
15119
|
raw;
|
|
@@ -14793,7 +15224,7 @@ var HonoRequest = class {
|
|
|
14793
15224
|
}
|
|
14794
15225
|
};
|
|
14795
15226
|
|
|
14796
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15227
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/html.js
|
|
14797
15228
|
var HtmlEscapedCallbackPhase = {
|
|
14798
15229
|
Stringify: 1,
|
|
14799
15230
|
BeforeStream: 2,
|
|
@@ -14831,7 +15262,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
|
|
|
14831
15262
|
}
|
|
14832
15263
|
};
|
|
14833
15264
|
|
|
14834
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15265
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/context.js
|
|
14835
15266
|
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
14836
15267
|
var setDefaultContentType = (contentType, headers) => {
|
|
14837
15268
|
return {
|
|
@@ -14998,7 +15429,7 @@ var Context = class {
|
|
|
14998
15429
|
};
|
|
14999
15430
|
};
|
|
15000
15431
|
|
|
15001
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15432
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router.js
|
|
15002
15433
|
var METHOD_NAME_ALL = "ALL";
|
|
15003
15434
|
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
15004
15435
|
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
@@ -15006,10 +15437,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
|
|
|
15006
15437
|
var UnsupportedPathError = class extends Error {
|
|
15007
15438
|
};
|
|
15008
15439
|
|
|
15009
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15440
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/constants.js
|
|
15010
15441
|
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
15011
15442
|
|
|
15012
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15443
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono-base.js
|
|
15013
15444
|
var notFoundHandler = (c) => {
|
|
15014
15445
|
return c.text("404 Not Found", 404);
|
|
15015
15446
|
};
|
|
@@ -15228,7 +15659,7 @@ var Hono = class _Hono {
|
|
|
15228
15659
|
};
|
|
15229
15660
|
};
|
|
15230
15661
|
|
|
15231
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15662
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
15232
15663
|
var emptyParam = [];
|
|
15233
15664
|
function match(method, path) {
|
|
15234
15665
|
const matchers = this.buildAllMatchers();
|
|
@@ -15249,7 +15680,7 @@ function match(method, path) {
|
|
|
15249
15680
|
return match2(method, path);
|
|
15250
15681
|
}
|
|
15251
15682
|
|
|
15252
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15683
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
15253
15684
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
15254
15685
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
15255
15686
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
@@ -15353,7 +15784,7 @@ var Node = class _Node {
|
|
|
15353
15784
|
}
|
|
15354
15785
|
};
|
|
15355
15786
|
|
|
15356
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15787
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
15357
15788
|
var Trie = class {
|
|
15358
15789
|
#context = { varIndex: 0 };
|
|
15359
15790
|
#root = new Node;
|
|
@@ -15409,7 +15840,7 @@ var Trie = class {
|
|
|
15409
15840
|
}
|
|
15410
15841
|
};
|
|
15411
15842
|
|
|
15412
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15843
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
15413
15844
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
15414
15845
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
15415
15846
|
function buildWildcardRegExp(path) {
|
|
@@ -15574,7 +16005,7 @@ var RegExpRouter = class {
|
|
|
15574
16005
|
}
|
|
15575
16006
|
};
|
|
15576
16007
|
|
|
15577
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16008
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
|
|
15578
16009
|
var PreparedRegExpRouter = class {
|
|
15579
16010
|
name = "PreparedRegExpRouter";
|
|
15580
16011
|
#matchers;
|
|
@@ -15646,7 +16077,7 @@ var PreparedRegExpRouter = class {
|
|
|
15646
16077
|
match = match;
|
|
15647
16078
|
};
|
|
15648
16079
|
|
|
15649
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16080
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/smart-router/router.js
|
|
15650
16081
|
var SmartRouter = class {
|
|
15651
16082
|
name = "SmartRouter";
|
|
15652
16083
|
#routers = [];
|
|
@@ -15701,7 +16132,7 @@ var SmartRouter = class {
|
|
|
15701
16132
|
}
|
|
15702
16133
|
};
|
|
15703
16134
|
|
|
15704
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16135
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/node.js
|
|
15705
16136
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
15706
16137
|
var hasChildren = (children) => {
|
|
15707
16138
|
for (const _ in children) {
|
|
@@ -15870,7 +16301,7 @@ var Node2 = class _Node2 {
|
|
|
15870
16301
|
}
|
|
15871
16302
|
};
|
|
15872
16303
|
|
|
15873
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16304
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/router.js
|
|
15874
16305
|
var TrieRouter = class {
|
|
15875
16306
|
name = "TrieRouter";
|
|
15876
16307
|
#node;
|
|
@@ -15892,7 +16323,7 @@ var TrieRouter = class {
|
|
|
15892
16323
|
}
|
|
15893
16324
|
};
|
|
15894
16325
|
|
|
15895
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16326
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono.js
|
|
15896
16327
|
var Hono2 = class extends Hono {
|
|
15897
16328
|
constructor(options = {}) {
|
|
15898
16329
|
super(options);
|
|
@@ -15992,12 +16423,12 @@ function requestIdMiddleware() {
|
|
|
15992
16423
|
};
|
|
15993
16424
|
}
|
|
15994
16425
|
function requestLoggerMiddleware(logger) {
|
|
15995
|
-
const
|
|
16426
|
+
const log14 = logger ?? createLogger();
|
|
15996
16427
|
return async (c, next) => {
|
|
15997
16428
|
const start = Date.now();
|
|
15998
16429
|
await next();
|
|
15999
16430
|
const duration = Date.now() - start;
|
|
16000
|
-
|
|
16431
|
+
log14.info(`${c.req.method} ${c.req.path}`, {
|
|
16001
16432
|
method: c.req.method,
|
|
16002
16433
|
path: c.req.path,
|
|
16003
16434
|
status: c.res.status,
|
|
@@ -16007,7 +16438,7 @@ function requestLoggerMiddleware(logger) {
|
|
|
16007
16438
|
};
|
|
16008
16439
|
}
|
|
16009
16440
|
|
|
16010
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16441
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/stream.js
|
|
16011
16442
|
var StreamingApi = class {
|
|
16012
16443
|
writer;
|
|
16013
16444
|
encoder;
|
|
@@ -16073,7 +16504,7 @@ var StreamingApi = class {
|
|
|
16073
16504
|
}
|
|
16074
16505
|
};
|
|
16075
16506
|
|
|
16076
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16507
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/utils.js
|
|
16077
16508
|
var isOldBunVersion = () => {
|
|
16078
16509
|
const version = typeof Bun !== "undefined" ? Bun.version : undefined;
|
|
16079
16510
|
if (version === undefined) {
|
|
@@ -16084,7 +16515,7 @@ var isOldBunVersion = () => {
|
|
|
16084
16515
|
return result;
|
|
16085
16516
|
};
|
|
16086
16517
|
|
|
16087
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16518
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/stream.js
|
|
16088
16519
|
var contextStash = /* @__PURE__ */ new WeakMap;
|
|
16089
16520
|
var stream = (c, cb, onError) => {
|
|
16090
16521
|
const { readable, writable } = new TransformStream;
|
|
@@ -16340,13 +16771,13 @@ function createRoutes(deps) {
|
|
|
16340
16771
|
}
|
|
16341
16772
|
|
|
16342
16773
|
// ../app/src/app.ts
|
|
16343
|
-
var
|
|
16774
|
+
var log14 = createLogger();
|
|
16344
16775
|
function createApp(config) {
|
|
16345
16776
|
const app = new Hono2;
|
|
16346
16777
|
app.onError((err2, c) => {
|
|
16347
16778
|
const statusCode = err2 instanceof ElsiumError ? err2.statusCode ?? 500 : 500;
|
|
16348
16779
|
const code = err2 instanceof ElsiumError ? err2.code : "UNKNOWN";
|
|
16349
|
-
|
|
16780
|
+
log14.error("Unhandled error", { error: err2.message, code, path: c.req.path });
|
|
16350
16781
|
return c.json({ error: err2.message, code }, statusCode);
|
|
16351
16782
|
});
|
|
16352
16783
|
app.notFound((c) => {
|
|
@@ -16392,7 +16823,7 @@ function createApp(config) {
|
|
|
16392
16823
|
});
|
|
16393
16824
|
const serverConfig = config.server ?? {};
|
|
16394
16825
|
app.use("*", requestIdMiddleware());
|
|
16395
|
-
app.use("*", requestLoggerMiddleware(
|
|
16826
|
+
app.use("*", requestLoggerMiddleware(log14));
|
|
16396
16827
|
if (serverConfig.cors) {
|
|
16397
16828
|
app.use("*", corsMiddleware(serverConfig.cors));
|
|
16398
16829
|
}
|
|
@@ -16438,11 +16869,11 @@ function createApp(config) {
|
|
|
16438
16869
|
const drainTimeoutMs = typeof serverConfig.gracefulShutdown === "object" ? serverConfig.gracefulShutdown.drainTimeoutMs : undefined;
|
|
16439
16870
|
shutdownManager = createShutdownManager({
|
|
16440
16871
|
drainTimeoutMs,
|
|
16441
|
-
onDrainStart: () =>
|
|
16442
|
-
onDrainComplete: () =>
|
|
16872
|
+
onDrainStart: () => log14.info("Draining connections..."),
|
|
16873
|
+
onDrainComplete: () => log14.info("Drain complete")
|
|
16443
16874
|
});
|
|
16444
16875
|
}
|
|
16445
|
-
|
|
16876
|
+
log14.info("ElsiumAI server started", {
|
|
16446
16877
|
url: `http://${hostname}:${listenPort}`,
|
|
16447
16878
|
routes: ["POST /chat", "POST /complete", "GET /health", "GET /metrics", "GET /agents"]
|
|
16448
16879
|
});
|
|
@@ -16459,9 +16890,9 @@ function createApp(config) {
|
|
|
16459
16890
|
};
|
|
16460
16891
|
}
|
|
16461
16892
|
// ../app/src/rbac.ts
|
|
16462
|
-
var
|
|
16893
|
+
var log15 = createLogger();
|
|
16463
16894
|
// ../app/src/tenant.ts
|
|
16464
|
-
var
|
|
16895
|
+
var log16 = createLogger();
|
|
16465
16896
|
var tenantUsage = new Map;
|
|
16466
16897
|
function tenantMiddleware(config) {
|
|
16467
16898
|
const { extractTenant, onUnknownTenant = "reject", defaultTenant } = config;
|
|
@@ -16470,13 +16901,13 @@ function tenantMiddleware(config) {
|
|
|
16470
16901
|
if (!tenant) {
|
|
16471
16902
|
if (onUnknownTenant === "default" && defaultTenant) {
|
|
16472
16903
|
c.set("tenant", defaultTenant);
|
|
16473
|
-
|
|
16904
|
+
log16.debug("Using default tenant", { tenantId: defaultTenant.tenantId });
|
|
16474
16905
|
} else {
|
|
16475
16906
|
return c.json({ error: "Tenant identification required" }, 401);
|
|
16476
16907
|
}
|
|
16477
16908
|
} else {
|
|
16478
16909
|
c.set("tenant", tenant);
|
|
16479
|
-
|
|
16910
|
+
log16.debug("Tenant identified", { tenantId: tenant.tenantId });
|
|
16480
16911
|
}
|
|
16481
16912
|
await next();
|
|
16482
16913
|
};
|
|
@@ -16910,7 +17341,7 @@ function createStdioMCPClient(config) {
|
|
|
16910
17341
|
};
|
|
16911
17342
|
}
|
|
16912
17343
|
// ../mcp/src/server.ts
|
|
16913
|
-
var
|
|
17344
|
+
var log17 = createLogger();
|
|
16914
17345
|
function createMCPServer(config) {
|
|
16915
17346
|
let running = false;
|
|
16916
17347
|
const toolMap = new Map(config.tools.map((t) => [t.name, t]));
|
|
@@ -17138,7 +17569,7 @@ function createMCPServer(config) {
|
|
|
17138
17569
|
pendingChunks.shift();
|
|
17139
17570
|
buffer += chunk;
|
|
17140
17571
|
if (buffer.length > MAX_BUFFER_SIZE2) {
|
|
17141
|
-
|
|
17572
|
+
log17.error("MCP server: buffer size limit exceeded, resetting");
|
|
17142
17573
|
buffer = "";
|
|
17143
17574
|
continue;
|
|
17144
17575
|
}
|
|
@@ -18119,7 +18550,7 @@ function createPromptRegistry() {
|
|
|
18119
18550
|
};
|
|
18120
18551
|
}
|
|
18121
18552
|
// ../testing/src/regression.ts
|
|
18122
|
-
import { mkdirSync as
|
|
18553
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
18123
18554
|
import { dirname } from "node:path";
|
|
18124
18555
|
function makeEmptyResult(name) {
|
|
18125
18556
|
return {
|
|
@@ -18188,7 +18619,7 @@ function createRegressionSuite(name) {
|
|
|
18188
18619
|
},
|
|
18189
18620
|
async load(path) {
|
|
18190
18621
|
try {
|
|
18191
|
-
const data =
|
|
18622
|
+
const data = readFileSync3(path, "utf-8");
|
|
18192
18623
|
baseline = JSON.parse(data);
|
|
18193
18624
|
} catch {
|
|
18194
18625
|
baseline = null;
|
|
@@ -18203,8 +18634,8 @@ function createRegressionSuite(name) {
|
|
|
18203
18634
|
updatedAt: Date.now()
|
|
18204
18635
|
};
|
|
18205
18636
|
}
|
|
18206
|
-
|
|
18207
|
-
|
|
18637
|
+
mkdirSync3(dirname(path), { recursive: true });
|
|
18638
|
+
writeFileSync4(path, JSON.stringify(baseline, null, 2));
|
|
18208
18639
|
},
|
|
18209
18640
|
addCase(input, output, score) {
|
|
18210
18641
|
if (!baseline) {
|
|
@@ -18274,6 +18705,203 @@ function createReplayPlayer(entriesOrJson) {
|
|
|
18274
18705
|
}
|
|
18275
18706
|
};
|
|
18276
18707
|
}
|
|
18708
|
+
// ../testing/src/dataset.ts
|
|
18709
|
+
import { readFile } from "node:fs/promises";
|
|
18710
|
+
import { extname } from "node:path";
|
|
18711
|
+
function mapRecordToCase(record, options) {
|
|
18712
|
+
const inputField = options?.inputField ?? "input";
|
|
18713
|
+
const expectedField = options?.expectedField ?? "expected";
|
|
18714
|
+
const nameField = options?.nameField ?? "name";
|
|
18715
|
+
const tagsField = options?.tagsField ?? "tags";
|
|
18716
|
+
const tags = record[tagsField];
|
|
18717
|
+
let parsedTags;
|
|
18718
|
+
if (typeof tags === "string") {
|
|
18719
|
+
parsedTags = tags.split(",").map((t) => t.trim()).filter(Boolean);
|
|
18720
|
+
} else if (Array.isArray(tags)) {
|
|
18721
|
+
parsedTags = tags.map(String);
|
|
18722
|
+
}
|
|
18723
|
+
return {
|
|
18724
|
+
name: String(record[nameField] ?? ""),
|
|
18725
|
+
input: String(record[inputField] ?? ""),
|
|
18726
|
+
expected: record[expectedField] !== undefined ? String(record[expectedField]) : undefined,
|
|
18727
|
+
tags: parsedTags
|
|
18728
|
+
};
|
|
18729
|
+
}
|
|
18730
|
+
async function loadDatasetFromJSON(path, options) {
|
|
18731
|
+
const content = await readFile(path, "utf-8");
|
|
18732
|
+
const parsed = JSON.parse(content);
|
|
18733
|
+
if (Array.isArray(parsed)) {
|
|
18734
|
+
return {
|
|
18735
|
+
name: "",
|
|
18736
|
+
cases: parsed.map((record) => mapRecordToCase(record, options))
|
|
18737
|
+
};
|
|
18738
|
+
}
|
|
18739
|
+
return {
|
|
18740
|
+
name: parsed.name ?? "",
|
|
18741
|
+
version: parsed.version,
|
|
18742
|
+
cases: (parsed.cases ?? []).map((record) => mapRecordToCase(record, options))
|
|
18743
|
+
};
|
|
18744
|
+
}
|
|
18745
|
+
function parseCSVLine2(line) {
|
|
18746
|
+
const fields = [];
|
|
18747
|
+
let current = "";
|
|
18748
|
+
let inQuotes = false;
|
|
18749
|
+
for (let i = 0;i < line.length; i++) {
|
|
18750
|
+
const char = line[i];
|
|
18751
|
+
if (inQuotes) {
|
|
18752
|
+
if (char === '"' && line[i + 1] === '"') {
|
|
18753
|
+
current += '"';
|
|
18754
|
+
i++;
|
|
18755
|
+
} else if (char === '"') {
|
|
18756
|
+
inQuotes = false;
|
|
18757
|
+
} else {
|
|
18758
|
+
current += char;
|
|
18759
|
+
}
|
|
18760
|
+
} else if (char === '"') {
|
|
18761
|
+
inQuotes = true;
|
|
18762
|
+
} else if (char === ",") {
|
|
18763
|
+
fields.push(current.trim());
|
|
18764
|
+
current = "";
|
|
18765
|
+
} else {
|
|
18766
|
+
current += char;
|
|
18767
|
+
}
|
|
18768
|
+
}
|
|
18769
|
+
fields.push(current.trim());
|
|
18770
|
+
return fields;
|
|
18771
|
+
}
|
|
18772
|
+
async function loadDatasetFromCSV(path, options) {
|
|
18773
|
+
const content = await readFile(path, "utf-8");
|
|
18774
|
+
const lines = content.split(`
|
|
18775
|
+
`).filter((line) => line.trim().length > 0);
|
|
18776
|
+
if (lines.length < 2) {
|
|
18777
|
+
return { name: "", cases: [] };
|
|
18778
|
+
}
|
|
18779
|
+
const headers = parseCSVLine2(lines[0]);
|
|
18780
|
+
const cases = [];
|
|
18781
|
+
for (let i = 1;i < lines.length; i++) {
|
|
18782
|
+
const values = parseCSVLine2(lines[i]);
|
|
18783
|
+
const record = {};
|
|
18784
|
+
for (let j = 0;j < headers.length; j++) {
|
|
18785
|
+
record[headers[j]] = values[j] ?? "";
|
|
18786
|
+
}
|
|
18787
|
+
cases.push(mapRecordToCase(record, options));
|
|
18788
|
+
}
|
|
18789
|
+
return { name: "", cases };
|
|
18790
|
+
}
|
|
18791
|
+
async function loadDatasetFromJSONL(path, options) {
|
|
18792
|
+
const content = await readFile(path, "utf-8");
|
|
18793
|
+
const lines = content.split(`
|
|
18794
|
+
`).filter((line) => line.trim().length > 0);
|
|
18795
|
+
const cases = lines.map((line) => mapRecordToCase(JSON.parse(line), options));
|
|
18796
|
+
return { name: "", cases };
|
|
18797
|
+
}
|
|
18798
|
+
async function loadDataset(path, options) {
|
|
18799
|
+
const ext = extname(path).toLowerCase();
|
|
18800
|
+
switch (ext) {
|
|
18801
|
+
case ".json":
|
|
18802
|
+
return loadDatasetFromJSON(path, options);
|
|
18803
|
+
case ".csv":
|
|
18804
|
+
return loadDatasetFromCSV(path, options);
|
|
18805
|
+
case ".jsonl":
|
|
18806
|
+
return loadDatasetFromJSONL(path, options);
|
|
18807
|
+
default:
|
|
18808
|
+
throw new Error(`Unsupported dataset format: ${ext}`);
|
|
18809
|
+
}
|
|
18810
|
+
}
|
|
18811
|
+
// ../testing/src/eval-compare.ts
|
|
18812
|
+
import { mkdir, readFile as readFile2, writeFile } from "node:fs/promises";
|
|
18813
|
+
import { join as join3 } from "node:path";
|
|
18814
|
+
async function saveBaseline(result, dir) {
|
|
18815
|
+
await mkdir(dir, { recursive: true });
|
|
18816
|
+
const baseline = {
|
|
18817
|
+
name: result.name,
|
|
18818
|
+
timestamp: Date.now(),
|
|
18819
|
+
score: result.score,
|
|
18820
|
+
results: result.results.map((r) => ({
|
|
18821
|
+
name: r.name,
|
|
18822
|
+
passed: r.passed,
|
|
18823
|
+
score: r.score
|
|
18824
|
+
}))
|
|
18825
|
+
};
|
|
18826
|
+
const filePath = join3(dir, `${result.name}.baseline.json`);
|
|
18827
|
+
await writeFile(filePath, JSON.stringify(baseline, null, "\t"), "utf-8");
|
|
18828
|
+
return filePath;
|
|
18829
|
+
}
|
|
18830
|
+
async function loadBaseline(name, dir) {
|
|
18831
|
+
const filePath = join3(dir, `${name}.baseline.json`);
|
|
18832
|
+
try {
|
|
18833
|
+
const content = await readFile2(filePath, "utf-8");
|
|
18834
|
+
return JSON.parse(content);
|
|
18835
|
+
} catch {
|
|
18836
|
+
return null;
|
|
18837
|
+
}
|
|
18838
|
+
}
|
|
18839
|
+
function compareResults(baseline, current) {
|
|
18840
|
+
const baselineMap = new Map(baseline.results.map((r) => [r.name, r]));
|
|
18841
|
+
const regressions = [];
|
|
18842
|
+
const improvements = [];
|
|
18843
|
+
for (const result of current.results) {
|
|
18844
|
+
const baselineResult = baselineMap.get(result.name);
|
|
18845
|
+
if (!baselineResult)
|
|
18846
|
+
continue;
|
|
18847
|
+
if (result.score < baselineResult.score) {
|
|
18848
|
+
regressions.push({
|
|
18849
|
+
name: result.name,
|
|
18850
|
+
baselineScore: baselineResult.score,
|
|
18851
|
+
currentScore: result.score
|
|
18852
|
+
});
|
|
18853
|
+
} else if (result.score > baselineResult.score) {
|
|
18854
|
+
improvements.push({
|
|
18855
|
+
name: result.name,
|
|
18856
|
+
baselineScore: baselineResult.score,
|
|
18857
|
+
currentScore: result.score
|
|
18858
|
+
});
|
|
18859
|
+
}
|
|
18860
|
+
}
|
|
18861
|
+
const delta = current.score - baseline.score;
|
|
18862
|
+
const hasFailedRegression = current.results.some((r) => {
|
|
18863
|
+
const base = baselineMap.get(r.name);
|
|
18864
|
+
return base?.passed && !r.passed;
|
|
18865
|
+
});
|
|
18866
|
+
return {
|
|
18867
|
+
baselineName: baseline.name,
|
|
18868
|
+
currentName: current.name,
|
|
18869
|
+
baselineScore: baseline.score,
|
|
18870
|
+
currentScore: current.score,
|
|
18871
|
+
delta,
|
|
18872
|
+
regressions,
|
|
18873
|
+
improvements,
|
|
18874
|
+
regression: delta < 0 || hasFailedRegression
|
|
18875
|
+
};
|
|
18876
|
+
}
|
|
18877
|
+
function formatComparison(comparison) {
|
|
18878
|
+
const lines = [];
|
|
18879
|
+
const deltaSign = comparison.delta >= 0 ? "+" : "";
|
|
18880
|
+
const deltaPercent = `${deltaSign}${(comparison.delta * 100).toFixed(1)}%`;
|
|
18881
|
+
lines.push(`
|
|
18882
|
+
Comparison: ${comparison.baselineName} -> ${comparison.currentName}`);
|
|
18883
|
+
lines.push(` ${"─".repeat(50)}`);
|
|
18884
|
+
lines.push(` Baseline: ${(comparison.baselineScore * 100).toFixed(1)}% | Current: ${(comparison.currentScore * 100).toFixed(1)}% | Delta: ${deltaPercent}`);
|
|
18885
|
+
if (comparison.regressions.length > 0) {
|
|
18886
|
+
lines.push(`
|
|
18887
|
+
Regressions (${comparison.regressions.length}):`);
|
|
18888
|
+
for (const r of comparison.regressions) {
|
|
18889
|
+
lines.push(` - ${r.name}: ${(r.baselineScore * 100).toFixed(1)}% -> ${(r.currentScore * 100).toFixed(1)}%`);
|
|
18890
|
+
}
|
|
18891
|
+
}
|
|
18892
|
+
if (comparison.improvements.length > 0) {
|
|
18893
|
+
lines.push(`
|
|
18894
|
+
Improvements (${comparison.improvements.length}):`);
|
|
18895
|
+
for (const imp of comparison.improvements) {
|
|
18896
|
+
lines.push(` + ${imp.name}: ${(imp.baselineScore * 100).toFixed(1)}% -> ${(imp.currentScore * 100).toFixed(1)}%`);
|
|
18897
|
+
}
|
|
18898
|
+
}
|
|
18899
|
+
lines.push(` ${"─".repeat(50)}`);
|
|
18900
|
+
lines.push(` Result: ${comparison.regression ? "REGRESSION DETECTED" : "OK"}`);
|
|
18901
|
+
lines.push("");
|
|
18902
|
+
return lines.join(`
|
|
18903
|
+
`);
|
|
18904
|
+
}
|
|
18277
18905
|
export {
|
|
18278
18906
|
zodToJsonSchema,
|
|
18279
18907
|
xrayMiddleware,
|
|
@@ -18296,6 +18924,7 @@ export {
|
|
|
18296
18924
|
shouldRequireApproval,
|
|
18297
18925
|
sentenceChunker,
|
|
18298
18926
|
securityMiddleware,
|
|
18927
|
+
saveBaseline,
|
|
18299
18928
|
runSupervisor,
|
|
18300
18929
|
runSequential,
|
|
18301
18930
|
runParallel,
|
|
@@ -18323,6 +18952,10 @@ export {
|
|
|
18323
18952
|
loggingMiddleware,
|
|
18324
18953
|
loadThread,
|
|
18325
18954
|
loadFixture,
|
|
18955
|
+
loadDatasetFromJSON,
|
|
18956
|
+
loadDatasetFromCSV,
|
|
18957
|
+
loadDataset,
|
|
18958
|
+
loadBaseline,
|
|
18326
18959
|
listProviders,
|
|
18327
18960
|
jsonParseTool,
|
|
18328
18961
|
jsonLoader,
|
|
@@ -18345,6 +18978,7 @@ export {
|
|
|
18345
18978
|
formatToolResult,
|
|
18346
18979
|
formatSSE,
|
|
18347
18980
|
formatEvalReport,
|
|
18981
|
+
formatComparison,
|
|
18348
18982
|
fixedSizeChunker,
|
|
18349
18983
|
extractTraceContext,
|
|
18350
18984
|
extractText,
|
|
@@ -18370,14 +19004,18 @@ export {
|
|
|
18370
19004
|
currentTimeTool,
|
|
18371
19005
|
csvLoader,
|
|
18372
19006
|
cronMatchesDate,
|
|
19007
|
+
createWebhookSink,
|
|
18373
19008
|
createWebhookChannel,
|
|
18374
19009
|
createToolkit,
|
|
18375
19010
|
createThread,
|
|
18376
19011
|
createSummarizeFn,
|
|
19012
|
+
createStudioExporter,
|
|
18377
19013
|
createStream,
|
|
18378
19014
|
createSqliteMemoryStore,
|
|
19015
|
+
createSplunkSink,
|
|
18379
19016
|
createSpan,
|
|
18380
19017
|
createSnapshotStore,
|
|
19018
|
+
createSinkManager,
|
|
18381
19019
|
createShutdownManager,
|
|
18382
19020
|
createSharedMemory,
|
|
18383
19021
|
createSessionRouter,
|
|
@@ -18418,6 +19056,7 @@ export {
|
|
|
18418
19056
|
createFileExperimentStore,
|
|
18419
19057
|
createExperiment,
|
|
18420
19058
|
createDedup,
|
|
19059
|
+
createDatadogSink,
|
|
18421
19060
|
createCostEngine,
|
|
18422
19061
|
createContextManager,
|
|
18423
19062
|
createConfidenceScorer,
|
|
@@ -18442,12 +19081,14 @@ export {
|
|
|
18442
19081
|
contentPolicy,
|
|
18443
19082
|
composeStreamMiddleware,
|
|
18444
19083
|
composeMiddleware,
|
|
19084
|
+
compareResults,
|
|
18445
19085
|
classifyContent,
|
|
18446
19086
|
checkBlockedPatterns,
|
|
18447
19087
|
calculatorTool,
|
|
18448
19088
|
calculateCost,
|
|
18449
19089
|
cacheMiddleware,
|
|
18450
19090
|
bulkheadMiddleware,
|
|
19091
|
+
auditStreamMiddleware,
|
|
18451
19092
|
auditMiddleware,
|
|
18452
19093
|
ElsiumStream,
|
|
18453
19094
|
ElsiumError
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elsium-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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.9.1",
|
|
29
|
+
"@elsium-ai/gateway": "^0.9.1",
|
|
30
|
+
"@elsium-ai/agents": "^0.9.1",
|
|
31
|
+
"@elsium-ai/tools": "^0.9.1",
|
|
32
|
+
"@elsium-ai/rag": "^0.9.1",
|
|
33
|
+
"@elsium-ai/workflows": "^0.9.1",
|
|
34
|
+
"@elsium-ai/observe": "^0.9.1",
|
|
35
|
+
"@elsium-ai/app": "^0.9.1",
|
|
36
|
+
"@elsium-ai/testing": "^0.9.1",
|
|
37
|
+
"@elsium-ai/mcp": "^0.9.1",
|
|
38
|
+
"@elsium-ai/client": "^0.9.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"typescript": "^5.7.0"
|