elsium-ai 0.8.0 → 0.9.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 +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +695 -60
- 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
|
});
|
|
@@ -3833,7 +3865,9 @@ function createProviderMesh(config) {
|
|
|
3833
3865
|
async function runStreamFallbackLoop(available, request, emit) {
|
|
3834
3866
|
let lastError = null;
|
|
3835
3867
|
let failedProvider = null;
|
|
3836
|
-
for (
|
|
3868
|
+
for (let i = 0;i < available.length; i++) {
|
|
3869
|
+
const entry = available[i];
|
|
3870
|
+
const nextProvider = i + 1 < available.length ? available[i + 1].name : "none";
|
|
3837
3871
|
try {
|
|
3838
3872
|
const result = await tryStreamProvider(entry, request, emit);
|
|
3839
3873
|
if (result.success) {
|
|
@@ -3843,11 +3877,11 @@ function createProviderMesh(config) {
|
|
|
3843
3877
|
}
|
|
3844
3878
|
lastError = result.error ?? null;
|
|
3845
3879
|
failedProvider = entry.name;
|
|
3846
|
-
logStreamFailover(entry.name, result.error);
|
|
3880
|
+
logStreamFailover(entry.name, nextProvider, result.error);
|
|
3847
3881
|
} catch (err2) {
|
|
3848
3882
|
failedProvider = entry.name;
|
|
3849
3883
|
lastError = toError2(err2);
|
|
3850
|
-
logStreamFailover(entry.name, lastError);
|
|
3884
|
+
logStreamFailover(entry.name, nextProvider, lastError);
|
|
3851
3885
|
}
|
|
3852
3886
|
}
|
|
3853
3887
|
emit({
|
|
@@ -13150,6 +13184,110 @@ function createMetrics(options) {
|
|
|
13150
13184
|
}
|
|
13151
13185
|
// ../observe/src/audit.ts
|
|
13152
13186
|
import { createHash as createHash3 } from "node:crypto";
|
|
13187
|
+
|
|
13188
|
+
// ../observe/src/audit-sink.ts
|
|
13189
|
+
var log10 = createLogger();
|
|
13190
|
+
function getRetryDelay2(attempt, baseDelayMs, maxDelayMs) {
|
|
13191
|
+
const delay = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);
|
|
13192
|
+
return delay * (0.5 + Math.random() * 0.5);
|
|
13193
|
+
}
|
|
13194
|
+
async function sendWithRetry(sink, events, retryConfig) {
|
|
13195
|
+
let lastError;
|
|
13196
|
+
for (let attempt = 0;attempt <= retryConfig.maxRetries; attempt++) {
|
|
13197
|
+
try {
|
|
13198
|
+
await sink.send(events);
|
|
13199
|
+
return;
|
|
13200
|
+
} catch (error) {
|
|
13201
|
+
lastError = error;
|
|
13202
|
+
if (attempt < retryConfig.maxRetries) {
|
|
13203
|
+
const delay = getRetryDelay2(attempt, retryConfig.baseDelayMs, retryConfig.maxDelayMs);
|
|
13204
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
13205
|
+
}
|
|
13206
|
+
}
|
|
13207
|
+
}
|
|
13208
|
+
throw lastError;
|
|
13209
|
+
}
|
|
13210
|
+
async function deliverToSink(sink, events, retryConfig, deadLetterSink, onError) {
|
|
13211
|
+
const filtered = sink.filter ? events.filter(sink.filter) : events;
|
|
13212
|
+
if (filtered.length === 0)
|
|
13213
|
+
return;
|
|
13214
|
+
try {
|
|
13215
|
+
await sendWithRetry(sink, filtered, retryConfig);
|
|
13216
|
+
} catch (error) {
|
|
13217
|
+
log10.error("Audit sink delivery failed", { sink: sink.name });
|
|
13218
|
+
onError?.(sink.name, error);
|
|
13219
|
+
if (!deadLetterSink)
|
|
13220
|
+
return;
|
|
13221
|
+
try {
|
|
13222
|
+
await deadLetterSink.send(filtered);
|
|
13223
|
+
} catch (dlqError) {
|
|
13224
|
+
log10.error("Dead letter sink delivery failed", { sink: deadLetterSink.name });
|
|
13225
|
+
onError?.(deadLetterSink.name, dlqError);
|
|
13226
|
+
}
|
|
13227
|
+
}
|
|
13228
|
+
}
|
|
13229
|
+
function createSinkManager(config) {
|
|
13230
|
+
const { sinks, onError, deadLetterSink } = config;
|
|
13231
|
+
const batchSize = config.batch?.size ?? 50;
|
|
13232
|
+
const batchIntervalMs = config.batch?.intervalMs ?? 5000;
|
|
13233
|
+
const maxBufferSize = config.maxBufferSize ?? 1e4;
|
|
13234
|
+
const retryConfig = {
|
|
13235
|
+
maxRetries: config.retry?.maxRetries ?? 3,
|
|
13236
|
+
baseDelayMs: config.retry?.baseDelayMs ?? 1000,
|
|
13237
|
+
maxDelayMs: config.retry?.maxDelayMs ?? 30000
|
|
13238
|
+
};
|
|
13239
|
+
const buffer = [];
|
|
13240
|
+
const inFlight = new Set;
|
|
13241
|
+
let flushTimer = null;
|
|
13242
|
+
function dispatchBatch(batch) {
|
|
13243
|
+
if (batch.length === 0 || sinks.length === 0)
|
|
13244
|
+
return;
|
|
13245
|
+
const promises = sinks.map((sink) => deliverToSink(sink, batch, retryConfig, deadLetterSink, onError));
|
|
13246
|
+
const combined = Promise.allSettled(promises).then(() => {
|
|
13247
|
+
inFlight.delete(combined);
|
|
13248
|
+
});
|
|
13249
|
+
inFlight.add(combined);
|
|
13250
|
+
}
|
|
13251
|
+
function drainBuffer() {
|
|
13252
|
+
while (buffer.length > 0) {
|
|
13253
|
+
const batch = buffer.splice(0, batchSize);
|
|
13254
|
+
dispatchBatch(batch);
|
|
13255
|
+
}
|
|
13256
|
+
}
|
|
13257
|
+
flushTimer = setInterval(() => {
|
|
13258
|
+
if (buffer.length > 0)
|
|
13259
|
+
drainBuffer();
|
|
13260
|
+
}, batchIntervalMs);
|
|
13261
|
+
if (typeof flushTimer === "object" && "unref" in flushTimer) {
|
|
13262
|
+
flushTimer.unref();
|
|
13263
|
+
}
|
|
13264
|
+
return {
|
|
13265
|
+
dispatch(event) {
|
|
13266
|
+
if (buffer.length >= maxBufferSize) {
|
|
13267
|
+
buffer.shift();
|
|
13268
|
+
log10.warn("Audit sink buffer full, dropping oldest event");
|
|
13269
|
+
}
|
|
13270
|
+
buffer.push(event);
|
|
13271
|
+
if (buffer.length >= batchSize)
|
|
13272
|
+
drainBuffer();
|
|
13273
|
+
},
|
|
13274
|
+
async flush() {
|
|
13275
|
+
drainBuffer();
|
|
13276
|
+
await Promise.allSettled([...inFlight]);
|
|
13277
|
+
},
|
|
13278
|
+
async shutdown() {
|
|
13279
|
+
if (flushTimer) {
|
|
13280
|
+
clearInterval(flushTimer);
|
|
13281
|
+
flushTimer = null;
|
|
13282
|
+
}
|
|
13283
|
+
drainBuffer();
|
|
13284
|
+
await Promise.allSettled([...inFlight]);
|
|
13285
|
+
await Promise.allSettled(sinks.map((sink) => sink.shutdown?.()));
|
|
13286
|
+
}
|
|
13287
|
+
};
|
|
13288
|
+
}
|
|
13289
|
+
|
|
13290
|
+
// ../observe/src/audit.ts
|
|
13153
13291
|
function computeEventHash(event, previousHash) {
|
|
13154
13292
|
const content = JSON.stringify({
|
|
13155
13293
|
id: event.id,
|
|
@@ -13258,16 +13396,34 @@ class InMemoryAuditStorage {
|
|
|
13258
13396
|
return last ? last.hash : ZERO_HASH;
|
|
13259
13397
|
}
|
|
13260
13398
|
}
|
|
13399
|
+
function resolveStorage(config) {
|
|
13400
|
+
if (config?.storage && typeof config.storage !== "string")
|
|
13401
|
+
return config.storage;
|
|
13402
|
+
return new InMemoryAuditStorage(config?.maxEvents);
|
|
13403
|
+
}
|
|
13404
|
+
function resolveSinkManager(config) {
|
|
13405
|
+
if (!config?.sinks)
|
|
13406
|
+
return null;
|
|
13407
|
+
const sinkConfig = Array.isArray(config.sinks) ? { sinks: config.sinks } : config.sinks;
|
|
13408
|
+
return createSinkManager(sinkConfig);
|
|
13409
|
+
}
|
|
13410
|
+
function resolveLastHash(storage) {
|
|
13411
|
+
if (!storage.getLastHash)
|
|
13412
|
+
return ZERO_HASH;
|
|
13413
|
+
return storage.getLastHash();
|
|
13414
|
+
}
|
|
13261
13415
|
function createAuditTrail(config) {
|
|
13262
13416
|
const useHashChain = config?.hashChain !== false;
|
|
13263
|
-
const storage =
|
|
13417
|
+
const storage = resolveStorage(config);
|
|
13418
|
+
const sinkManager = resolveSinkManager(config);
|
|
13419
|
+
const globalContext = config?.context;
|
|
13264
13420
|
let sequenceId = 0;
|
|
13265
13421
|
let idCounter = 0;
|
|
13266
13422
|
let previousHash = ZERO_HASH;
|
|
13267
13423
|
let isReady = true;
|
|
13268
13424
|
let readyPromise = Promise.resolve();
|
|
13269
|
-
if (useHashChain
|
|
13270
|
-
const lastHash = storage
|
|
13425
|
+
if (useHashChain) {
|
|
13426
|
+
const lastHash = resolveLastHash(storage);
|
|
13271
13427
|
if (typeof lastHash === "string") {
|
|
13272
13428
|
previousHash = lastHash;
|
|
13273
13429
|
} else {
|
|
@@ -13285,10 +13441,11 @@ function createAuditTrail(config) {
|
|
|
13285
13441
|
const isBatched = !!batchConfig;
|
|
13286
13442
|
const pendingBuffer = [];
|
|
13287
13443
|
let flushTimer = null;
|
|
13288
|
-
|
|
13444
|
+
let flushPromise = Promise.resolve();
|
|
13289
13445
|
function buildAndAppend(entry) {
|
|
13290
13446
|
sequenceId++;
|
|
13291
13447
|
idCounter++;
|
|
13448
|
+
const data = globalContext ? { ...globalContext, ...entry.data } : entry.data;
|
|
13292
13449
|
const event = {
|
|
13293
13450
|
id: `audit_${idCounter.toString(36)}_${entry.timestamp.toString(36)}`,
|
|
13294
13451
|
sequenceId,
|
|
@@ -13296,7 +13453,7 @@ function createAuditTrail(config) {
|
|
|
13296
13453
|
timestamp: entry.timestamp,
|
|
13297
13454
|
actor: entry.actor,
|
|
13298
13455
|
traceId: entry.traceId,
|
|
13299
|
-
data
|
|
13456
|
+
data,
|
|
13300
13457
|
previousHash: useHashChain ? previousHash : ZERO_HASH
|
|
13301
13458
|
};
|
|
13302
13459
|
const hash = useHashChain ? computeEventHash(event, event.previousHash) : createHash3("sha256").update(JSON.stringify(event)).digest("hex");
|
|
@@ -13305,9 +13462,10 @@ function createAuditTrail(config) {
|
|
|
13305
13462
|
previousHash = hash;
|
|
13306
13463
|
}
|
|
13307
13464
|
const result = storage.append(finalEvent);
|
|
13308
|
-
if (result && typeof result.
|
|
13309
|
-
result.catch((err2) => config?.onError?.(err2));
|
|
13465
|
+
if (result && typeof result.then === "function") {
|
|
13466
|
+
flushPromise = flushPromise.then(() => result).catch((err2) => config?.onError?.(err2));
|
|
13310
13467
|
}
|
|
13468
|
+
sinkManager?.dispatch(finalEvent);
|
|
13311
13469
|
}
|
|
13312
13470
|
function drainBuffer() {
|
|
13313
13471
|
let entry = pendingBuffer.shift();
|
|
@@ -13356,13 +13514,16 @@ function createAuditTrail(config) {
|
|
|
13356
13514
|
await readyPromise;
|
|
13357
13515
|
drainBuffer();
|
|
13358
13516
|
await flushPromise;
|
|
13517
|
+
await sinkManager?.flush();
|
|
13359
13518
|
},
|
|
13360
|
-
dispose() {
|
|
13519
|
+
async dispose() {
|
|
13361
13520
|
if (flushTimer) {
|
|
13362
13521
|
clearInterval(flushTimer);
|
|
13363
13522
|
flushTimer = null;
|
|
13364
13523
|
}
|
|
13365
13524
|
drainBuffer();
|
|
13525
|
+
await flushPromise;
|
|
13526
|
+
await sinkManager?.shutdown();
|
|
13366
13527
|
},
|
|
13367
13528
|
async query(filter) {
|
|
13368
13529
|
if (isBatched)
|
|
@@ -13413,6 +13574,203 @@ function auditMiddleware(auditTrail) {
|
|
|
13413
13574
|
}
|
|
13414
13575
|
};
|
|
13415
13576
|
}
|
|
13577
|
+
function emitStreamAudit(auditTrail, ctx, state, latencyMs) {
|
|
13578
|
+
if (state.hasError && !state.hasUsage) {
|
|
13579
|
+
auditTrail.log("llm_call", {
|
|
13580
|
+
provider: ctx.provider,
|
|
13581
|
+
model: ctx.model,
|
|
13582
|
+
error: state.errorMessage,
|
|
13583
|
+
latencyMs,
|
|
13584
|
+
success: false,
|
|
13585
|
+
streaming: true
|
|
13586
|
+
}, { traceId: ctx.traceId });
|
|
13587
|
+
} else if (state.hasUsage) {
|
|
13588
|
+
auditTrail.log("llm_call", {
|
|
13589
|
+
provider: ctx.provider,
|
|
13590
|
+
model: ctx.model,
|
|
13591
|
+
inputTokens: state.inputTokens,
|
|
13592
|
+
outputTokens: state.outputTokens,
|
|
13593
|
+
totalTokens: state.totalTokens,
|
|
13594
|
+
latencyMs,
|
|
13595
|
+
stopReason: state.stopReason,
|
|
13596
|
+
streaming: true
|
|
13597
|
+
}, { traceId: ctx.traceId });
|
|
13598
|
+
}
|
|
13599
|
+
}
|
|
13600
|
+
function auditStreamMiddleware(auditTrail) {
|
|
13601
|
+
return (ctx, source, next) => {
|
|
13602
|
+
const startTime = performance.now();
|
|
13603
|
+
const processed = next(ctx, source);
|
|
13604
|
+
return async function* () {
|
|
13605
|
+
const state = {
|
|
13606
|
+
inputTokens: 0,
|
|
13607
|
+
outputTokens: 0,
|
|
13608
|
+
totalTokens: 0,
|
|
13609
|
+
hasUsage: false,
|
|
13610
|
+
hasError: false
|
|
13611
|
+
};
|
|
13612
|
+
try {
|
|
13613
|
+
for await (const event of processed) {
|
|
13614
|
+
if (event.type === "message_end") {
|
|
13615
|
+
state.inputTokens = event.usage.inputTokens;
|
|
13616
|
+
state.outputTokens = event.usage.outputTokens;
|
|
13617
|
+
state.totalTokens = event.usage.totalTokens;
|
|
13618
|
+
state.stopReason = event.stopReason;
|
|
13619
|
+
state.hasUsage = true;
|
|
13620
|
+
}
|
|
13621
|
+
if (event.type === "error") {
|
|
13622
|
+
state.hasError = true;
|
|
13623
|
+
state.errorMessage = event.error.message;
|
|
13624
|
+
}
|
|
13625
|
+
yield event;
|
|
13626
|
+
}
|
|
13627
|
+
} finally {
|
|
13628
|
+
const latencyMs = Math.round(performance.now() - startTime);
|
|
13629
|
+
emitStreamAudit(auditTrail, ctx, state, latencyMs);
|
|
13630
|
+
}
|
|
13631
|
+
}();
|
|
13632
|
+
};
|
|
13633
|
+
}
|
|
13634
|
+
// ../observe/src/audit-sink-webhook.ts
|
|
13635
|
+
function createWebhookSink(config) {
|
|
13636
|
+
const { url, headers = {}, method = "POST", timeoutMs = 1e4 } = config;
|
|
13637
|
+
return {
|
|
13638
|
+
name: "webhook",
|
|
13639
|
+
async send(events) {
|
|
13640
|
+
const controller = new AbortController;
|
|
13641
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13642
|
+
try {
|
|
13643
|
+
const response = await fetch(url, {
|
|
13644
|
+
method,
|
|
13645
|
+
headers: {
|
|
13646
|
+
"Content-Type": "application/json",
|
|
13647
|
+
...headers
|
|
13648
|
+
},
|
|
13649
|
+
body: JSON.stringify({ events }),
|
|
13650
|
+
signal: controller.signal
|
|
13651
|
+
});
|
|
13652
|
+
if (!response.ok) {
|
|
13653
|
+
throw new Error(`Webhook responded with ${response.status} ${response.statusText}`);
|
|
13654
|
+
}
|
|
13655
|
+
} catch (error) {
|
|
13656
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13657
|
+
throw new Error(`Webhook request timed out after ${timeoutMs}ms`);
|
|
13658
|
+
}
|
|
13659
|
+
throw error;
|
|
13660
|
+
} finally {
|
|
13661
|
+
clearTimeout(timeout);
|
|
13662
|
+
}
|
|
13663
|
+
}
|
|
13664
|
+
};
|
|
13665
|
+
}
|
|
13666
|
+
// ../observe/src/audit-sink-splunk.ts
|
|
13667
|
+
function toSplunkEvent(event, index, source, sourcetype) {
|
|
13668
|
+
return JSON.stringify({
|
|
13669
|
+
time: event.timestamp / 1000,
|
|
13670
|
+
source: source ?? "elsium-ai",
|
|
13671
|
+
sourcetype: sourcetype ?? "elsium:audit",
|
|
13672
|
+
...index && { index },
|
|
13673
|
+
event
|
|
13674
|
+
});
|
|
13675
|
+
}
|
|
13676
|
+
function createSplunkSink(config) {
|
|
13677
|
+
const { url, token, index, source, sourcetype, timeoutMs = 1e4 } = config;
|
|
13678
|
+
return {
|
|
13679
|
+
name: "splunk",
|
|
13680
|
+
async send(events) {
|
|
13681
|
+
const body = events.map((e) => toSplunkEvent(e, index, source, sourcetype)).join(`
|
|
13682
|
+
`);
|
|
13683
|
+
const controller = new AbortController;
|
|
13684
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13685
|
+
try {
|
|
13686
|
+
const response = await fetch(url, {
|
|
13687
|
+
method: "POST",
|
|
13688
|
+
headers: {
|
|
13689
|
+
Authorization: `Splunk ${token}`,
|
|
13690
|
+
"Content-Type": "application/json"
|
|
13691
|
+
},
|
|
13692
|
+
body,
|
|
13693
|
+
signal: controller.signal
|
|
13694
|
+
});
|
|
13695
|
+
if (!response.ok) {
|
|
13696
|
+
throw new Error(`Splunk HEC responded with ${response.status} ${response.statusText}`);
|
|
13697
|
+
}
|
|
13698
|
+
} catch (error) {
|
|
13699
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13700
|
+
throw new Error(`Splunk HEC request timed out after ${timeoutMs}ms`);
|
|
13701
|
+
}
|
|
13702
|
+
throw error;
|
|
13703
|
+
} finally {
|
|
13704
|
+
clearTimeout(timeout);
|
|
13705
|
+
}
|
|
13706
|
+
}
|
|
13707
|
+
};
|
|
13708
|
+
}
|
|
13709
|
+
// ../observe/src/audit-sink-datadog.ts
|
|
13710
|
+
function formatTags(tags) {
|
|
13711
|
+
return Object.entries(tags).map(([k, v]) => `${k}:${v}`).join(",");
|
|
13712
|
+
}
|
|
13713
|
+
function toDatadogLog(event, service, source, tags) {
|
|
13714
|
+
return {
|
|
13715
|
+
ddsource: source,
|
|
13716
|
+
ddtags: tags ? formatTags(tags) : undefined,
|
|
13717
|
+
service,
|
|
13718
|
+
hostname: "elsium-ai",
|
|
13719
|
+
message: `[${event.type}] ${JSON.stringify(event.data)}`,
|
|
13720
|
+
status: event.type === "security_violation" ? "error" : "info",
|
|
13721
|
+
timestamp: event.timestamp,
|
|
13722
|
+
audit: {
|
|
13723
|
+
id: event.id,
|
|
13724
|
+
sequenceId: event.sequenceId,
|
|
13725
|
+
type: event.type,
|
|
13726
|
+
actor: event.actor,
|
|
13727
|
+
traceId: event.traceId,
|
|
13728
|
+
data: event.data,
|
|
13729
|
+
hash: event.hash,
|
|
13730
|
+
previousHash: event.previousHash
|
|
13731
|
+
}
|
|
13732
|
+
};
|
|
13733
|
+
}
|
|
13734
|
+
function createDatadogSink(config) {
|
|
13735
|
+
const {
|
|
13736
|
+
apiKey,
|
|
13737
|
+
site = "datadoghq.com",
|
|
13738
|
+
service = "elsium-ai",
|
|
13739
|
+
source = "elsium-ai-audit",
|
|
13740
|
+
tags,
|
|
13741
|
+
timeoutMs = 1e4
|
|
13742
|
+
} = config;
|
|
13743
|
+
const endpoint = `https://http-intake.logs.${site}/api/v2/logs`;
|
|
13744
|
+
return {
|
|
13745
|
+
name: "datadog",
|
|
13746
|
+
async send(events) {
|
|
13747
|
+
const body = events.map((e) => toDatadogLog(e, service, source, tags));
|
|
13748
|
+
const controller = new AbortController;
|
|
13749
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
13750
|
+
try {
|
|
13751
|
+
const response = await fetch(endpoint, {
|
|
13752
|
+
method: "POST",
|
|
13753
|
+
headers: {
|
|
13754
|
+
"DD-API-KEY": apiKey,
|
|
13755
|
+
"Content-Type": "application/json"
|
|
13756
|
+
},
|
|
13757
|
+
body: JSON.stringify(body),
|
|
13758
|
+
signal: controller.signal
|
|
13759
|
+
});
|
|
13760
|
+
if (!response.ok) {
|
|
13761
|
+
throw new Error(`Datadog Log Intake responded with ${response.status} ${response.statusText}`);
|
|
13762
|
+
}
|
|
13763
|
+
} catch (error) {
|
|
13764
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
13765
|
+
throw new Error(`Datadog request timed out after ${timeoutMs}ms`);
|
|
13766
|
+
}
|
|
13767
|
+
throw error;
|
|
13768
|
+
} finally {
|
|
13769
|
+
clearTimeout(timeout);
|
|
13770
|
+
}
|
|
13771
|
+
}
|
|
13772
|
+
};
|
|
13773
|
+
}
|
|
13416
13774
|
// ../observe/src/provenance.ts
|
|
13417
13775
|
import { createHash as createHash4 } from "node:crypto";
|
|
13418
13776
|
function sha256(input) {
|
|
@@ -13474,7 +13832,7 @@ function createProvenanceTracker(options) {
|
|
|
13474
13832
|
import { createHash as createHash5 } from "node:crypto";
|
|
13475
13833
|
import { existsSync, mkdirSync, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
13476
13834
|
import { join } from "node:path";
|
|
13477
|
-
var
|
|
13835
|
+
var log11 = createLogger();
|
|
13478
13836
|
function createFileExperimentStore(dir) {
|
|
13479
13837
|
return {
|
|
13480
13838
|
save(name, data) {
|
|
@@ -13485,7 +13843,7 @@ function createFileExperimentStore(dir) {
|
|
|
13485
13843
|
const filePath = join(dir, `${name}.json`);
|
|
13486
13844
|
writeFileSync2(filePath, JSON.stringify(data, null, 2));
|
|
13487
13845
|
} catch (err2) {
|
|
13488
|
-
|
|
13846
|
+
log11.error("Failed to save experiment", {
|
|
13489
13847
|
name,
|
|
13490
13848
|
error: err2 instanceof Error ? err2.message : String(err2)
|
|
13491
13849
|
});
|
|
@@ -13516,7 +13874,7 @@ function loadFromStore(store, name, stats) {
|
|
|
13516
13874
|
stats[vName].metrics[key] = { sum: m.sum, count: m.count };
|
|
13517
13875
|
}
|
|
13518
13876
|
}
|
|
13519
|
-
|
|
13877
|
+
log11.debug("Loaded experiment state", { name, totalAssignments: saved.totalAssignments });
|
|
13520
13878
|
}
|
|
13521
13879
|
function recordMetrics(s, metrics) {
|
|
13522
13880
|
for (const [key, value] of Object.entries(metrics)) {
|
|
@@ -13584,7 +13942,7 @@ function createExperiment(config) {
|
|
|
13584
13942
|
const s = stats[variant.name];
|
|
13585
13943
|
if (s)
|
|
13586
13944
|
s.assignments++;
|
|
13587
|
-
|
|
13945
|
+
log11.debug("Experiment assignment", {
|
|
13588
13946
|
experiment: name,
|
|
13589
13947
|
variant: variant.name,
|
|
13590
13948
|
userId
|
|
@@ -13652,8 +14010,72 @@ function instrumentAgent(agent, tracer) {
|
|
|
13652
14010
|
};
|
|
13653
14011
|
return instrumented;
|
|
13654
14012
|
}
|
|
14013
|
+
// ../observe/src/studio-exporter.ts
|
|
14014
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
14015
|
+
import { join as join2 } from "node:path";
|
|
14016
|
+
var log12 = createLogger();
|
|
14017
|
+
function ensureDir(dirPath) {
|
|
14018
|
+
if (!existsSync2(dirPath)) {
|
|
14019
|
+
mkdirSync2(dirPath, { recursive: true });
|
|
14020
|
+
}
|
|
14021
|
+
}
|
|
14022
|
+
function safeWriteJSON(filePath, data) {
|
|
14023
|
+
try {
|
|
14024
|
+
writeFileSync3(filePath, JSON.stringify(data, null, 2));
|
|
14025
|
+
} catch (err2) {
|
|
14026
|
+
log12.error("Studio exporter write failed", {
|
|
14027
|
+
file: filePath,
|
|
14028
|
+
error: err2 instanceof Error ? err2.message : String(err2)
|
|
14029
|
+
});
|
|
14030
|
+
}
|
|
14031
|
+
}
|
|
14032
|
+
function safeReadJSON(filePath, fallback) {
|
|
14033
|
+
try {
|
|
14034
|
+
if (!existsSync2(filePath))
|
|
14035
|
+
return fallback;
|
|
14036
|
+
return JSON.parse(readFileSync2(filePath, "utf-8"));
|
|
14037
|
+
} catch {
|
|
14038
|
+
return fallback;
|
|
14039
|
+
}
|
|
14040
|
+
}
|
|
14041
|
+
function createStudioExporter(config) {
|
|
14042
|
+
const baseDir = config?.dir ?? ".elsium";
|
|
14043
|
+
const tracesDir = join2(baseDir, "traces");
|
|
14044
|
+
const xrayFile = join2(baseDir, "xray-history.json");
|
|
14045
|
+
const costFile = join2(baseDir, "cost-report.json");
|
|
14046
|
+
ensureDir(tracesDir);
|
|
14047
|
+
return {
|
|
14048
|
+
name: "studio",
|
|
14049
|
+
export(spans) {
|
|
14050
|
+
for (const span of spans) {
|
|
14051
|
+
if (!span.traceId)
|
|
14052
|
+
continue;
|
|
14053
|
+
const filePath = join2(tracesDir, `${span.traceId}.json`);
|
|
14054
|
+
safeWriteJSON(filePath, span);
|
|
14055
|
+
}
|
|
14056
|
+
},
|
|
14057
|
+
writeXRayEntry(entry) {
|
|
14058
|
+
const history = safeReadJSON(xrayFile, []);
|
|
14059
|
+
history.unshift(entry);
|
|
14060
|
+
if (history.length > 500)
|
|
14061
|
+
history.length = 500;
|
|
14062
|
+
safeWriteJSON(xrayFile, history);
|
|
14063
|
+
},
|
|
14064
|
+
writeCostReport(report) {
|
|
14065
|
+
safeWriteJSON(costFile, {
|
|
14066
|
+
totalRequests: report.callCount,
|
|
14067
|
+
totalTokens: report.totalTokens,
|
|
14068
|
+
totalCost: report.totalCost,
|
|
14069
|
+
byModel: Object.fromEntries(Object.entries(report.byModel).map(([model, data]) => [
|
|
14070
|
+
model,
|
|
14071
|
+
{ requests: data.calls, tokens: data.tokens, cost: data.cost }
|
|
14072
|
+
]))
|
|
14073
|
+
});
|
|
14074
|
+
}
|
|
14075
|
+
};
|
|
14076
|
+
}
|
|
13655
14077
|
// ../observe/src/otel.ts
|
|
13656
|
-
var
|
|
14078
|
+
var log13 = createLogger();
|
|
13657
14079
|
var SPAN_KIND_MAP = {
|
|
13658
14080
|
llm: 3,
|
|
13659
14081
|
tool: 1,
|
|
@@ -13794,10 +14216,10 @@ function createOTLPExporter(config) {
|
|
|
13794
14216
|
body: JSON.stringify(payload)
|
|
13795
14217
|
});
|
|
13796
14218
|
if (!response.ok) {
|
|
13797
|
-
|
|
14219
|
+
log13.error(`OTLP export failed: ${response.status} ${response.statusText}`);
|
|
13798
14220
|
}
|
|
13799
14221
|
} catch (err2) {
|
|
13800
|
-
|
|
14222
|
+
log13.error("OTLP export error", { error: err2 instanceof Error ? err2.message : String(err2) });
|
|
13801
14223
|
}
|
|
13802
14224
|
}
|
|
13803
14225
|
function startAutoFlush() {
|
|
@@ -14367,7 +14789,7 @@ var serve = (options, listeningListener) => {
|
|
|
14367
14789
|
return server;
|
|
14368
14790
|
};
|
|
14369
14791
|
|
|
14370
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14792
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/compose.js
|
|
14371
14793
|
var compose = (middleware, onError, onNotFound) => {
|
|
14372
14794
|
return (context, next) => {
|
|
14373
14795
|
let index = -1;
|
|
@@ -14411,10 +14833,10 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
14411
14833
|
};
|
|
14412
14834
|
};
|
|
14413
14835
|
|
|
14414
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14836
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request/constants.js
|
|
14415
14837
|
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
14416
14838
|
|
|
14417
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14839
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/body.js
|
|
14418
14840
|
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
14419
14841
|
const { all = false, dot = false } = options;
|
|
14420
14842
|
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
@@ -14468,6 +14890,9 @@ var handleParsingAllValues = (form, key, value) => {
|
|
|
14468
14890
|
}
|
|
14469
14891
|
};
|
|
14470
14892
|
var handleParsingNestedValues = (form, key, value) => {
|
|
14893
|
+
if (/(?:^|\.)__proto__\./.test(key)) {
|
|
14894
|
+
return;
|
|
14895
|
+
}
|
|
14471
14896
|
let nestedForm = form;
|
|
14472
14897
|
const keys = key.split(".");
|
|
14473
14898
|
keys.forEach((key2, index) => {
|
|
@@ -14482,7 +14907,7 @@ var handleParsingNestedValues = (form, key, value) => {
|
|
|
14482
14907
|
});
|
|
14483
14908
|
};
|
|
14484
14909
|
|
|
14485
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
14910
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/url.js
|
|
14486
14911
|
var splitPath = (path) => {
|
|
14487
14912
|
const paths = path.split("/");
|
|
14488
14913
|
if (paths[0] === "") {
|
|
@@ -14682,7 +15107,7 @@ var getQueryParams = (url, key) => {
|
|
|
14682
15107
|
};
|
|
14683
15108
|
var decodeURIComponent_ = decodeURIComponent;
|
|
14684
15109
|
|
|
14685
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15110
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request.js
|
|
14686
15111
|
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
14687
15112
|
var HonoRequest = class {
|
|
14688
15113
|
raw;
|
|
@@ -14793,7 +15218,7 @@ var HonoRequest = class {
|
|
|
14793
15218
|
}
|
|
14794
15219
|
};
|
|
14795
15220
|
|
|
14796
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15221
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/html.js
|
|
14797
15222
|
var HtmlEscapedCallbackPhase = {
|
|
14798
15223
|
Stringify: 1,
|
|
14799
15224
|
BeforeStream: 2,
|
|
@@ -14831,7 +15256,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
|
|
|
14831
15256
|
}
|
|
14832
15257
|
};
|
|
14833
15258
|
|
|
14834
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15259
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/context.js
|
|
14835
15260
|
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
14836
15261
|
var setDefaultContentType = (contentType, headers) => {
|
|
14837
15262
|
return {
|
|
@@ -14998,7 +15423,7 @@ var Context = class {
|
|
|
14998
15423
|
};
|
|
14999
15424
|
};
|
|
15000
15425
|
|
|
15001
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15426
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router.js
|
|
15002
15427
|
var METHOD_NAME_ALL = "ALL";
|
|
15003
15428
|
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
15004
15429
|
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
@@ -15006,10 +15431,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
|
|
|
15006
15431
|
var UnsupportedPathError = class extends Error {
|
|
15007
15432
|
};
|
|
15008
15433
|
|
|
15009
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15434
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/constants.js
|
|
15010
15435
|
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
15011
15436
|
|
|
15012
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15437
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono-base.js
|
|
15013
15438
|
var notFoundHandler = (c) => {
|
|
15014
15439
|
return c.text("404 Not Found", 404);
|
|
15015
15440
|
};
|
|
@@ -15228,7 +15653,7 @@ var Hono = class _Hono {
|
|
|
15228
15653
|
};
|
|
15229
15654
|
};
|
|
15230
15655
|
|
|
15231
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15656
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
15232
15657
|
var emptyParam = [];
|
|
15233
15658
|
function match(method, path) {
|
|
15234
15659
|
const matchers = this.buildAllMatchers();
|
|
@@ -15249,7 +15674,7 @@ function match(method, path) {
|
|
|
15249
15674
|
return match2(method, path);
|
|
15250
15675
|
}
|
|
15251
15676
|
|
|
15252
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15677
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
15253
15678
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
15254
15679
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
15255
15680
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
@@ -15353,7 +15778,7 @@ var Node = class _Node {
|
|
|
15353
15778
|
}
|
|
15354
15779
|
};
|
|
15355
15780
|
|
|
15356
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15781
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
15357
15782
|
var Trie = class {
|
|
15358
15783
|
#context = { varIndex: 0 };
|
|
15359
15784
|
#root = new Node;
|
|
@@ -15409,7 +15834,7 @@ var Trie = class {
|
|
|
15409
15834
|
}
|
|
15410
15835
|
};
|
|
15411
15836
|
|
|
15412
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
15837
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
15413
15838
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
15414
15839
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
15415
15840
|
function buildWildcardRegExp(path) {
|
|
@@ -15574,7 +15999,7 @@ var RegExpRouter = class {
|
|
|
15574
15999
|
}
|
|
15575
16000
|
};
|
|
15576
16001
|
|
|
15577
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16002
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
|
|
15578
16003
|
var PreparedRegExpRouter = class {
|
|
15579
16004
|
name = "PreparedRegExpRouter";
|
|
15580
16005
|
#matchers;
|
|
@@ -15646,7 +16071,7 @@ var PreparedRegExpRouter = class {
|
|
|
15646
16071
|
match = match;
|
|
15647
16072
|
};
|
|
15648
16073
|
|
|
15649
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16074
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/smart-router/router.js
|
|
15650
16075
|
var SmartRouter = class {
|
|
15651
16076
|
name = "SmartRouter";
|
|
15652
16077
|
#routers = [];
|
|
@@ -15701,7 +16126,7 @@ var SmartRouter = class {
|
|
|
15701
16126
|
}
|
|
15702
16127
|
};
|
|
15703
16128
|
|
|
15704
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16129
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/node.js
|
|
15705
16130
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
15706
16131
|
var hasChildren = (children) => {
|
|
15707
16132
|
for (const _ in children) {
|
|
@@ -15870,7 +16295,7 @@ var Node2 = class _Node2 {
|
|
|
15870
16295
|
}
|
|
15871
16296
|
};
|
|
15872
16297
|
|
|
15873
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16298
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/router.js
|
|
15874
16299
|
var TrieRouter = class {
|
|
15875
16300
|
name = "TrieRouter";
|
|
15876
16301
|
#node;
|
|
@@ -15892,7 +16317,7 @@ var TrieRouter = class {
|
|
|
15892
16317
|
}
|
|
15893
16318
|
};
|
|
15894
16319
|
|
|
15895
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16320
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono.js
|
|
15896
16321
|
var Hono2 = class extends Hono {
|
|
15897
16322
|
constructor(options = {}) {
|
|
15898
16323
|
super(options);
|
|
@@ -15992,12 +16417,12 @@ function requestIdMiddleware() {
|
|
|
15992
16417
|
};
|
|
15993
16418
|
}
|
|
15994
16419
|
function requestLoggerMiddleware(logger) {
|
|
15995
|
-
const
|
|
16420
|
+
const log14 = logger ?? createLogger();
|
|
15996
16421
|
return async (c, next) => {
|
|
15997
16422
|
const start = Date.now();
|
|
15998
16423
|
await next();
|
|
15999
16424
|
const duration = Date.now() - start;
|
|
16000
|
-
|
|
16425
|
+
log14.info(`${c.req.method} ${c.req.path}`, {
|
|
16001
16426
|
method: c.req.method,
|
|
16002
16427
|
path: c.req.path,
|
|
16003
16428
|
status: c.res.status,
|
|
@@ -16007,7 +16432,7 @@ function requestLoggerMiddleware(logger) {
|
|
|
16007
16432
|
};
|
|
16008
16433
|
}
|
|
16009
16434
|
|
|
16010
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16435
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/stream.js
|
|
16011
16436
|
var StreamingApi = class {
|
|
16012
16437
|
writer;
|
|
16013
16438
|
encoder;
|
|
@@ -16073,7 +16498,7 @@ var StreamingApi = class {
|
|
|
16073
16498
|
}
|
|
16074
16499
|
};
|
|
16075
16500
|
|
|
16076
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16501
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/utils.js
|
|
16077
16502
|
var isOldBunVersion = () => {
|
|
16078
16503
|
const version = typeof Bun !== "undefined" ? Bun.version : undefined;
|
|
16079
16504
|
if (version === undefined) {
|
|
@@ -16084,7 +16509,7 @@ var isOldBunVersion = () => {
|
|
|
16084
16509
|
return result;
|
|
16085
16510
|
};
|
|
16086
16511
|
|
|
16087
|
-
// ../../node_modules/.bun/hono@4.12.
|
|
16512
|
+
// ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/stream.js
|
|
16088
16513
|
var contextStash = /* @__PURE__ */ new WeakMap;
|
|
16089
16514
|
var stream = (c, cb, onError) => {
|
|
16090
16515
|
const { readable, writable } = new TransformStream;
|
|
@@ -16340,13 +16765,13 @@ function createRoutes(deps) {
|
|
|
16340
16765
|
}
|
|
16341
16766
|
|
|
16342
16767
|
// ../app/src/app.ts
|
|
16343
|
-
var
|
|
16768
|
+
var log14 = createLogger();
|
|
16344
16769
|
function createApp(config) {
|
|
16345
16770
|
const app = new Hono2;
|
|
16346
16771
|
app.onError((err2, c) => {
|
|
16347
16772
|
const statusCode = err2 instanceof ElsiumError ? err2.statusCode ?? 500 : 500;
|
|
16348
16773
|
const code = err2 instanceof ElsiumError ? err2.code : "UNKNOWN";
|
|
16349
|
-
|
|
16774
|
+
log14.error("Unhandled error", { error: err2.message, code, path: c.req.path });
|
|
16350
16775
|
return c.json({ error: err2.message, code }, statusCode);
|
|
16351
16776
|
});
|
|
16352
16777
|
app.notFound((c) => {
|
|
@@ -16392,7 +16817,7 @@ function createApp(config) {
|
|
|
16392
16817
|
});
|
|
16393
16818
|
const serverConfig = config.server ?? {};
|
|
16394
16819
|
app.use("*", requestIdMiddleware());
|
|
16395
|
-
app.use("*", requestLoggerMiddleware(
|
|
16820
|
+
app.use("*", requestLoggerMiddleware(log14));
|
|
16396
16821
|
if (serverConfig.cors) {
|
|
16397
16822
|
app.use("*", corsMiddleware(serverConfig.cors));
|
|
16398
16823
|
}
|
|
@@ -16438,11 +16863,11 @@ function createApp(config) {
|
|
|
16438
16863
|
const drainTimeoutMs = typeof serverConfig.gracefulShutdown === "object" ? serverConfig.gracefulShutdown.drainTimeoutMs : undefined;
|
|
16439
16864
|
shutdownManager = createShutdownManager({
|
|
16440
16865
|
drainTimeoutMs,
|
|
16441
|
-
onDrainStart: () =>
|
|
16442
|
-
onDrainComplete: () =>
|
|
16866
|
+
onDrainStart: () => log14.info("Draining connections..."),
|
|
16867
|
+
onDrainComplete: () => log14.info("Drain complete")
|
|
16443
16868
|
});
|
|
16444
16869
|
}
|
|
16445
|
-
|
|
16870
|
+
log14.info("ElsiumAI server started", {
|
|
16446
16871
|
url: `http://${hostname}:${listenPort}`,
|
|
16447
16872
|
routes: ["POST /chat", "POST /complete", "GET /health", "GET /metrics", "GET /agents"]
|
|
16448
16873
|
});
|
|
@@ -16459,9 +16884,9 @@ function createApp(config) {
|
|
|
16459
16884
|
};
|
|
16460
16885
|
}
|
|
16461
16886
|
// ../app/src/rbac.ts
|
|
16462
|
-
var
|
|
16887
|
+
var log15 = createLogger();
|
|
16463
16888
|
// ../app/src/tenant.ts
|
|
16464
|
-
var
|
|
16889
|
+
var log16 = createLogger();
|
|
16465
16890
|
var tenantUsage = new Map;
|
|
16466
16891
|
function tenantMiddleware(config) {
|
|
16467
16892
|
const { extractTenant, onUnknownTenant = "reject", defaultTenant } = config;
|
|
@@ -16470,13 +16895,13 @@ function tenantMiddleware(config) {
|
|
|
16470
16895
|
if (!tenant) {
|
|
16471
16896
|
if (onUnknownTenant === "default" && defaultTenant) {
|
|
16472
16897
|
c.set("tenant", defaultTenant);
|
|
16473
|
-
|
|
16898
|
+
log16.debug("Using default tenant", { tenantId: defaultTenant.tenantId });
|
|
16474
16899
|
} else {
|
|
16475
16900
|
return c.json({ error: "Tenant identification required" }, 401);
|
|
16476
16901
|
}
|
|
16477
16902
|
} else {
|
|
16478
16903
|
c.set("tenant", tenant);
|
|
16479
|
-
|
|
16904
|
+
log16.debug("Tenant identified", { tenantId: tenant.tenantId });
|
|
16480
16905
|
}
|
|
16481
16906
|
await next();
|
|
16482
16907
|
};
|
|
@@ -16910,7 +17335,7 @@ function createStdioMCPClient(config) {
|
|
|
16910
17335
|
};
|
|
16911
17336
|
}
|
|
16912
17337
|
// ../mcp/src/server.ts
|
|
16913
|
-
var
|
|
17338
|
+
var log17 = createLogger();
|
|
16914
17339
|
function createMCPServer(config) {
|
|
16915
17340
|
let running = false;
|
|
16916
17341
|
const toolMap = new Map(config.tools.map((t) => [t.name, t]));
|
|
@@ -17138,7 +17563,7 @@ function createMCPServer(config) {
|
|
|
17138
17563
|
pendingChunks.shift();
|
|
17139
17564
|
buffer += chunk;
|
|
17140
17565
|
if (buffer.length > MAX_BUFFER_SIZE2) {
|
|
17141
|
-
|
|
17566
|
+
log17.error("MCP server: buffer size limit exceeded, resetting");
|
|
17142
17567
|
buffer = "";
|
|
17143
17568
|
continue;
|
|
17144
17569
|
}
|
|
@@ -18119,7 +18544,7 @@ function createPromptRegistry() {
|
|
|
18119
18544
|
};
|
|
18120
18545
|
}
|
|
18121
18546
|
// ../testing/src/regression.ts
|
|
18122
|
-
import { mkdirSync as
|
|
18547
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
18123
18548
|
import { dirname } from "node:path";
|
|
18124
18549
|
function makeEmptyResult(name) {
|
|
18125
18550
|
return {
|
|
@@ -18188,7 +18613,7 @@ function createRegressionSuite(name) {
|
|
|
18188
18613
|
},
|
|
18189
18614
|
async load(path) {
|
|
18190
18615
|
try {
|
|
18191
|
-
const data =
|
|
18616
|
+
const data = readFileSync3(path, "utf-8");
|
|
18192
18617
|
baseline = JSON.parse(data);
|
|
18193
18618
|
} catch {
|
|
18194
18619
|
baseline = null;
|
|
@@ -18203,8 +18628,8 @@ function createRegressionSuite(name) {
|
|
|
18203
18628
|
updatedAt: Date.now()
|
|
18204
18629
|
};
|
|
18205
18630
|
}
|
|
18206
|
-
|
|
18207
|
-
|
|
18631
|
+
mkdirSync3(dirname(path), { recursive: true });
|
|
18632
|
+
writeFileSync4(path, JSON.stringify(baseline, null, 2));
|
|
18208
18633
|
},
|
|
18209
18634
|
addCase(input, output, score) {
|
|
18210
18635
|
if (!baseline) {
|
|
@@ -18274,6 +18699,203 @@ function createReplayPlayer(entriesOrJson) {
|
|
|
18274
18699
|
}
|
|
18275
18700
|
};
|
|
18276
18701
|
}
|
|
18702
|
+
// ../testing/src/dataset.ts
|
|
18703
|
+
import { readFile } from "node:fs/promises";
|
|
18704
|
+
import { extname } from "node:path";
|
|
18705
|
+
function mapRecordToCase(record, options) {
|
|
18706
|
+
const inputField = options?.inputField ?? "input";
|
|
18707
|
+
const expectedField = options?.expectedField ?? "expected";
|
|
18708
|
+
const nameField = options?.nameField ?? "name";
|
|
18709
|
+
const tagsField = options?.tagsField ?? "tags";
|
|
18710
|
+
const tags = record[tagsField];
|
|
18711
|
+
let parsedTags;
|
|
18712
|
+
if (typeof tags === "string") {
|
|
18713
|
+
parsedTags = tags.split(",").map((t) => t.trim()).filter(Boolean);
|
|
18714
|
+
} else if (Array.isArray(tags)) {
|
|
18715
|
+
parsedTags = tags.map(String);
|
|
18716
|
+
}
|
|
18717
|
+
return {
|
|
18718
|
+
name: String(record[nameField] ?? ""),
|
|
18719
|
+
input: String(record[inputField] ?? ""),
|
|
18720
|
+
expected: record[expectedField] !== undefined ? String(record[expectedField]) : undefined,
|
|
18721
|
+
tags: parsedTags
|
|
18722
|
+
};
|
|
18723
|
+
}
|
|
18724
|
+
async function loadDatasetFromJSON(path, options) {
|
|
18725
|
+
const content = await readFile(path, "utf-8");
|
|
18726
|
+
const parsed = JSON.parse(content);
|
|
18727
|
+
if (Array.isArray(parsed)) {
|
|
18728
|
+
return {
|
|
18729
|
+
name: "",
|
|
18730
|
+
cases: parsed.map((record) => mapRecordToCase(record, options))
|
|
18731
|
+
};
|
|
18732
|
+
}
|
|
18733
|
+
return {
|
|
18734
|
+
name: parsed.name ?? "",
|
|
18735
|
+
version: parsed.version,
|
|
18736
|
+
cases: (parsed.cases ?? []).map((record) => mapRecordToCase(record, options))
|
|
18737
|
+
};
|
|
18738
|
+
}
|
|
18739
|
+
function parseCSVLine2(line) {
|
|
18740
|
+
const fields = [];
|
|
18741
|
+
let current = "";
|
|
18742
|
+
let inQuotes = false;
|
|
18743
|
+
for (let i = 0;i < line.length; i++) {
|
|
18744
|
+
const char = line[i];
|
|
18745
|
+
if (inQuotes) {
|
|
18746
|
+
if (char === '"' && line[i + 1] === '"') {
|
|
18747
|
+
current += '"';
|
|
18748
|
+
i++;
|
|
18749
|
+
} else if (char === '"') {
|
|
18750
|
+
inQuotes = false;
|
|
18751
|
+
} else {
|
|
18752
|
+
current += char;
|
|
18753
|
+
}
|
|
18754
|
+
} else if (char === '"') {
|
|
18755
|
+
inQuotes = true;
|
|
18756
|
+
} else if (char === ",") {
|
|
18757
|
+
fields.push(current.trim());
|
|
18758
|
+
current = "";
|
|
18759
|
+
} else {
|
|
18760
|
+
current += char;
|
|
18761
|
+
}
|
|
18762
|
+
}
|
|
18763
|
+
fields.push(current.trim());
|
|
18764
|
+
return fields;
|
|
18765
|
+
}
|
|
18766
|
+
async function loadDatasetFromCSV(path, options) {
|
|
18767
|
+
const content = await readFile(path, "utf-8");
|
|
18768
|
+
const lines = content.split(`
|
|
18769
|
+
`).filter((line) => line.trim().length > 0);
|
|
18770
|
+
if (lines.length < 2) {
|
|
18771
|
+
return { name: "", cases: [] };
|
|
18772
|
+
}
|
|
18773
|
+
const headers = parseCSVLine2(lines[0]);
|
|
18774
|
+
const cases = [];
|
|
18775
|
+
for (let i = 1;i < lines.length; i++) {
|
|
18776
|
+
const values = parseCSVLine2(lines[i]);
|
|
18777
|
+
const record = {};
|
|
18778
|
+
for (let j = 0;j < headers.length; j++) {
|
|
18779
|
+
record[headers[j]] = values[j] ?? "";
|
|
18780
|
+
}
|
|
18781
|
+
cases.push(mapRecordToCase(record, options));
|
|
18782
|
+
}
|
|
18783
|
+
return { name: "", cases };
|
|
18784
|
+
}
|
|
18785
|
+
async function loadDatasetFromJSONL(path, options) {
|
|
18786
|
+
const content = await readFile(path, "utf-8");
|
|
18787
|
+
const lines = content.split(`
|
|
18788
|
+
`).filter((line) => line.trim().length > 0);
|
|
18789
|
+
const cases = lines.map((line) => mapRecordToCase(JSON.parse(line), options));
|
|
18790
|
+
return { name: "", cases };
|
|
18791
|
+
}
|
|
18792
|
+
async function loadDataset(path, options) {
|
|
18793
|
+
const ext = extname(path).toLowerCase();
|
|
18794
|
+
switch (ext) {
|
|
18795
|
+
case ".json":
|
|
18796
|
+
return loadDatasetFromJSON(path, options);
|
|
18797
|
+
case ".csv":
|
|
18798
|
+
return loadDatasetFromCSV(path, options);
|
|
18799
|
+
case ".jsonl":
|
|
18800
|
+
return loadDatasetFromJSONL(path, options);
|
|
18801
|
+
default:
|
|
18802
|
+
throw new Error(`Unsupported dataset format: ${ext}`);
|
|
18803
|
+
}
|
|
18804
|
+
}
|
|
18805
|
+
// ../testing/src/eval-compare.ts
|
|
18806
|
+
import { mkdir, readFile as readFile2, writeFile } from "node:fs/promises";
|
|
18807
|
+
import { join as join3 } from "node:path";
|
|
18808
|
+
async function saveBaseline(result, dir) {
|
|
18809
|
+
await mkdir(dir, { recursive: true });
|
|
18810
|
+
const baseline = {
|
|
18811
|
+
name: result.name,
|
|
18812
|
+
timestamp: Date.now(),
|
|
18813
|
+
score: result.score,
|
|
18814
|
+
results: result.results.map((r) => ({
|
|
18815
|
+
name: r.name,
|
|
18816
|
+
passed: r.passed,
|
|
18817
|
+
score: r.score
|
|
18818
|
+
}))
|
|
18819
|
+
};
|
|
18820
|
+
const filePath = join3(dir, `${result.name}.baseline.json`);
|
|
18821
|
+
await writeFile(filePath, JSON.stringify(baseline, null, "\t"), "utf-8");
|
|
18822
|
+
return filePath;
|
|
18823
|
+
}
|
|
18824
|
+
async function loadBaseline(name, dir) {
|
|
18825
|
+
const filePath = join3(dir, `${name}.baseline.json`);
|
|
18826
|
+
try {
|
|
18827
|
+
const content = await readFile2(filePath, "utf-8");
|
|
18828
|
+
return JSON.parse(content);
|
|
18829
|
+
} catch {
|
|
18830
|
+
return null;
|
|
18831
|
+
}
|
|
18832
|
+
}
|
|
18833
|
+
function compareResults(baseline, current) {
|
|
18834
|
+
const baselineMap = new Map(baseline.results.map((r) => [r.name, r]));
|
|
18835
|
+
const regressions = [];
|
|
18836
|
+
const improvements = [];
|
|
18837
|
+
for (const result of current.results) {
|
|
18838
|
+
const baselineResult = baselineMap.get(result.name);
|
|
18839
|
+
if (!baselineResult)
|
|
18840
|
+
continue;
|
|
18841
|
+
if (result.score < baselineResult.score) {
|
|
18842
|
+
regressions.push({
|
|
18843
|
+
name: result.name,
|
|
18844
|
+
baselineScore: baselineResult.score,
|
|
18845
|
+
currentScore: result.score
|
|
18846
|
+
});
|
|
18847
|
+
} else if (result.score > baselineResult.score) {
|
|
18848
|
+
improvements.push({
|
|
18849
|
+
name: result.name,
|
|
18850
|
+
baselineScore: baselineResult.score,
|
|
18851
|
+
currentScore: result.score
|
|
18852
|
+
});
|
|
18853
|
+
}
|
|
18854
|
+
}
|
|
18855
|
+
const delta = current.score - baseline.score;
|
|
18856
|
+
const hasFailedRegression = current.results.some((r) => {
|
|
18857
|
+
const base = baselineMap.get(r.name);
|
|
18858
|
+
return base?.passed && !r.passed;
|
|
18859
|
+
});
|
|
18860
|
+
return {
|
|
18861
|
+
baselineName: baseline.name,
|
|
18862
|
+
currentName: current.name,
|
|
18863
|
+
baselineScore: baseline.score,
|
|
18864
|
+
currentScore: current.score,
|
|
18865
|
+
delta,
|
|
18866
|
+
regressions,
|
|
18867
|
+
improvements,
|
|
18868
|
+
regression: delta < 0 || hasFailedRegression
|
|
18869
|
+
};
|
|
18870
|
+
}
|
|
18871
|
+
function formatComparison(comparison) {
|
|
18872
|
+
const lines = [];
|
|
18873
|
+
const deltaSign = comparison.delta >= 0 ? "+" : "";
|
|
18874
|
+
const deltaPercent = `${deltaSign}${(comparison.delta * 100).toFixed(1)}%`;
|
|
18875
|
+
lines.push(`
|
|
18876
|
+
Comparison: ${comparison.baselineName} -> ${comparison.currentName}`);
|
|
18877
|
+
lines.push(` ${"─".repeat(50)}`);
|
|
18878
|
+
lines.push(` Baseline: ${(comparison.baselineScore * 100).toFixed(1)}% | Current: ${(comparison.currentScore * 100).toFixed(1)}% | Delta: ${deltaPercent}`);
|
|
18879
|
+
if (comparison.regressions.length > 0) {
|
|
18880
|
+
lines.push(`
|
|
18881
|
+
Regressions (${comparison.regressions.length}):`);
|
|
18882
|
+
for (const r of comparison.regressions) {
|
|
18883
|
+
lines.push(` - ${r.name}: ${(r.baselineScore * 100).toFixed(1)}% -> ${(r.currentScore * 100).toFixed(1)}%`);
|
|
18884
|
+
}
|
|
18885
|
+
}
|
|
18886
|
+
if (comparison.improvements.length > 0) {
|
|
18887
|
+
lines.push(`
|
|
18888
|
+
Improvements (${comparison.improvements.length}):`);
|
|
18889
|
+
for (const imp of comparison.improvements) {
|
|
18890
|
+
lines.push(` + ${imp.name}: ${(imp.baselineScore * 100).toFixed(1)}% -> ${(imp.currentScore * 100).toFixed(1)}%`);
|
|
18891
|
+
}
|
|
18892
|
+
}
|
|
18893
|
+
lines.push(` ${"─".repeat(50)}`);
|
|
18894
|
+
lines.push(` Result: ${comparison.regression ? "REGRESSION DETECTED" : "OK"}`);
|
|
18895
|
+
lines.push("");
|
|
18896
|
+
return lines.join(`
|
|
18897
|
+
`);
|
|
18898
|
+
}
|
|
18277
18899
|
export {
|
|
18278
18900
|
zodToJsonSchema,
|
|
18279
18901
|
xrayMiddleware,
|
|
@@ -18296,6 +18918,7 @@ export {
|
|
|
18296
18918
|
shouldRequireApproval,
|
|
18297
18919
|
sentenceChunker,
|
|
18298
18920
|
securityMiddleware,
|
|
18921
|
+
saveBaseline,
|
|
18299
18922
|
runSupervisor,
|
|
18300
18923
|
runSequential,
|
|
18301
18924
|
runParallel,
|
|
@@ -18323,6 +18946,10 @@ export {
|
|
|
18323
18946
|
loggingMiddleware,
|
|
18324
18947
|
loadThread,
|
|
18325
18948
|
loadFixture,
|
|
18949
|
+
loadDatasetFromJSON,
|
|
18950
|
+
loadDatasetFromCSV,
|
|
18951
|
+
loadDataset,
|
|
18952
|
+
loadBaseline,
|
|
18326
18953
|
listProviders,
|
|
18327
18954
|
jsonParseTool,
|
|
18328
18955
|
jsonLoader,
|
|
@@ -18345,6 +18972,7 @@ export {
|
|
|
18345
18972
|
formatToolResult,
|
|
18346
18973
|
formatSSE,
|
|
18347
18974
|
formatEvalReport,
|
|
18975
|
+
formatComparison,
|
|
18348
18976
|
fixedSizeChunker,
|
|
18349
18977
|
extractTraceContext,
|
|
18350
18978
|
extractText,
|
|
@@ -18370,14 +18998,18 @@ export {
|
|
|
18370
18998
|
currentTimeTool,
|
|
18371
18999
|
csvLoader,
|
|
18372
19000
|
cronMatchesDate,
|
|
19001
|
+
createWebhookSink,
|
|
18373
19002
|
createWebhookChannel,
|
|
18374
19003
|
createToolkit,
|
|
18375
19004
|
createThread,
|
|
18376
19005
|
createSummarizeFn,
|
|
19006
|
+
createStudioExporter,
|
|
18377
19007
|
createStream,
|
|
18378
19008
|
createSqliteMemoryStore,
|
|
19009
|
+
createSplunkSink,
|
|
18379
19010
|
createSpan,
|
|
18380
19011
|
createSnapshotStore,
|
|
19012
|
+
createSinkManager,
|
|
18381
19013
|
createShutdownManager,
|
|
18382
19014
|
createSharedMemory,
|
|
18383
19015
|
createSessionRouter,
|
|
@@ -18418,6 +19050,7 @@ export {
|
|
|
18418
19050
|
createFileExperimentStore,
|
|
18419
19051
|
createExperiment,
|
|
18420
19052
|
createDedup,
|
|
19053
|
+
createDatadogSink,
|
|
18421
19054
|
createCostEngine,
|
|
18422
19055
|
createContextManager,
|
|
18423
19056
|
createConfidenceScorer,
|
|
@@ -18442,12 +19075,14 @@ export {
|
|
|
18442
19075
|
contentPolicy,
|
|
18443
19076
|
composeStreamMiddleware,
|
|
18444
19077
|
composeMiddleware,
|
|
19078
|
+
compareResults,
|
|
18445
19079
|
classifyContent,
|
|
18446
19080
|
checkBlockedPatterns,
|
|
18447
19081
|
calculatorTool,
|
|
18448
19082
|
calculateCost,
|
|
18449
19083
|
cacheMiddleware,
|
|
18450
19084
|
bulkheadMiddleware,
|
|
19085
|
+
auditStreamMiddleware,
|
|
18451
19086
|
auditMiddleware,
|
|
18452
19087
|
ElsiumStream,
|
|
18453
19088
|
ElsiumError
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elsium-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.9.0",
|
|
29
|
+
"@elsium-ai/gateway": "^0.9.0",
|
|
30
|
+
"@elsium-ai/agents": "^0.9.0",
|
|
31
|
+
"@elsium-ai/tools": "^0.9.0",
|
|
32
|
+
"@elsium-ai/rag": "^0.9.0",
|
|
33
|
+
"@elsium-ai/workflows": "^0.9.0",
|
|
34
|
+
"@elsium-ai/observe": "^0.9.0",
|
|
35
|
+
"@elsium-ai/app": "^0.9.0",
|
|
36
|
+
"@elsium-ai/testing": "^0.9.0",
|
|
37
|
+
"@elsium-ai/mcp": "^0.9.0",
|
|
38
|
+
"@elsium-ai/client": "^0.9.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"typescript": "^5.7.0"
|