@nuvin/nuvin-core 1.1.2 → 1.3.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/VERSION +2 -2
- package/dist/index.d.ts +127 -10
- package/dist/index.js +843 -478
- package/package.json +1 -1
package/dist/VERSION
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -237,6 +237,7 @@ type ChatMessage = {
|
|
|
237
237
|
tool_calls?: ToolCall[];
|
|
238
238
|
tool_call_id?: string;
|
|
239
239
|
name?: string;
|
|
240
|
+
[key: string]: unknown;
|
|
240
241
|
};
|
|
241
242
|
type CompletionParams = {
|
|
242
243
|
messages: ChatMessage[];
|
|
@@ -264,6 +265,7 @@ type CompletionParams = {
|
|
|
264
265
|
usage?: {
|
|
265
266
|
include?: boolean;
|
|
266
267
|
};
|
|
268
|
+
[key: string]: unknown;
|
|
267
269
|
};
|
|
268
270
|
type UsageData = {
|
|
269
271
|
prompt_tokens?: number;
|
|
@@ -286,6 +288,7 @@ type CompletionResult = {
|
|
|
286
288
|
content: string;
|
|
287
289
|
tool_calls?: ToolCall[];
|
|
288
290
|
usage?: UsageData;
|
|
291
|
+
[key: string]: unknown;
|
|
289
292
|
};
|
|
290
293
|
type Message = {
|
|
291
294
|
id: string;
|
|
@@ -296,6 +299,7 @@ type Message = {
|
|
|
296
299
|
tool_call_id?: string;
|
|
297
300
|
name?: string;
|
|
298
301
|
usage?: UsageData;
|
|
302
|
+
[key: string]: unknown;
|
|
299
303
|
};
|
|
300
304
|
type MessageResponse = {
|
|
301
305
|
id: string;
|
|
@@ -335,6 +339,14 @@ interface LLMPort {
|
|
|
335
339
|
onToolCallDelta?: (tc: ToolCall) => void;
|
|
336
340
|
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
337
341
|
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
342
|
+
getModels?(signal?: AbortSignal): Promise<Array<{
|
|
343
|
+
id: string;
|
|
344
|
+
limits?: {
|
|
345
|
+
contextWindow: number;
|
|
346
|
+
maxOutput?: number;
|
|
347
|
+
};
|
|
348
|
+
[key: string]: unknown;
|
|
349
|
+
}>>;
|
|
338
350
|
}
|
|
339
351
|
type LLMConfig = {
|
|
340
352
|
provider?: string;
|
|
@@ -432,6 +444,33 @@ interface Clock {
|
|
|
432
444
|
interface CostCalculator {
|
|
433
445
|
estimate(model: string, usage?: UsageData): number | undefined;
|
|
434
446
|
}
|
|
447
|
+
type MetricsSnapshot = {
|
|
448
|
+
totalTokens: number;
|
|
449
|
+
totalPromptTokens: number;
|
|
450
|
+
totalCompletionTokens: number;
|
|
451
|
+
totalCachedTokens: number;
|
|
452
|
+
totalReasoningTokens: number;
|
|
453
|
+
requestCount: number;
|
|
454
|
+
llmCallCount: number;
|
|
455
|
+
toolCallCount: number;
|
|
456
|
+
totalTimeMs: number;
|
|
457
|
+
totalCost: number;
|
|
458
|
+
currentTokens: number;
|
|
459
|
+
currentPromptTokens: number;
|
|
460
|
+
currentCompletionTokens: number;
|
|
461
|
+
currentCachedTokens: number;
|
|
462
|
+
currentCost: number;
|
|
463
|
+
contextWindowLimit?: number;
|
|
464
|
+
contextWindowUsage?: number;
|
|
465
|
+
};
|
|
466
|
+
interface MetricsPort {
|
|
467
|
+
recordLLMCall(usage: UsageData, cost?: number): void;
|
|
468
|
+
recordToolCall(): void;
|
|
469
|
+
recordRequestComplete(responseTimeMs: number): void;
|
|
470
|
+
setContextWindow(limit: number, usage: number): void;
|
|
471
|
+
reset(): void;
|
|
472
|
+
getSnapshot(): MetricsSnapshot;
|
|
473
|
+
}
|
|
435
474
|
type AgentConfig = {
|
|
436
475
|
id: string;
|
|
437
476
|
systemPrompt: string;
|
|
@@ -575,17 +614,27 @@ interface EventPort {
|
|
|
575
614
|
|
|
576
615
|
declare class AgentOrchestrator {
|
|
577
616
|
private cfg;
|
|
578
|
-
private deps;
|
|
579
617
|
private pendingApprovals;
|
|
618
|
+
private context;
|
|
619
|
+
private ids;
|
|
620
|
+
private clock;
|
|
621
|
+
private cost;
|
|
622
|
+
private reminders;
|
|
623
|
+
private metrics;
|
|
624
|
+
private events?;
|
|
625
|
+
private llm?;
|
|
626
|
+
private tools;
|
|
627
|
+
private memory;
|
|
580
628
|
constructor(cfg: AgentConfig, deps: {
|
|
581
629
|
memory: MemoryPort<Message>;
|
|
582
|
-
llm: LLMPort;
|
|
583
630
|
tools: ToolPort;
|
|
584
|
-
context
|
|
585
|
-
ids
|
|
586
|
-
clock
|
|
587
|
-
cost
|
|
588
|
-
reminders
|
|
631
|
+
context?: ContextBuilder;
|
|
632
|
+
ids?: IdGenerator$1;
|
|
633
|
+
clock?: Clock;
|
|
634
|
+
cost?: CostCalculator;
|
|
635
|
+
reminders?: RemindersPort;
|
|
636
|
+
llm?: LLMPort;
|
|
637
|
+
metrics?: MetricsPort;
|
|
589
638
|
events?: EventPort;
|
|
590
639
|
});
|
|
591
640
|
/**
|
|
@@ -610,7 +659,7 @@ declare class AgentOrchestrator {
|
|
|
610
659
|
/**
|
|
611
660
|
* Gets the current LLM port.
|
|
612
661
|
*/
|
|
613
|
-
getLLM(): LLMPort;
|
|
662
|
+
getLLM(): LLMPort | undefined;
|
|
614
663
|
/**
|
|
615
664
|
* Gets the current agent configuration.
|
|
616
665
|
*/
|
|
@@ -626,6 +675,14 @@ declare class AgentOrchestrator {
|
|
|
626
675
|
* This is useful when switching to a new session with a different event log file.
|
|
627
676
|
*/
|
|
628
677
|
setEvents(newEvents: EventPort): void;
|
|
678
|
+
/**
|
|
679
|
+
* Updates the metrics port without reinitializing the entire orchestrator.
|
|
680
|
+
*/
|
|
681
|
+
setMetrics(newMetrics: MetricsPort): void;
|
|
682
|
+
/**
|
|
683
|
+
* Gets the current metrics port.
|
|
684
|
+
*/
|
|
685
|
+
getMetrics(): MetricsPort | undefined;
|
|
629
686
|
/**
|
|
630
687
|
* Determines if a tool should bypass approval requirements.
|
|
631
688
|
* Read-only tools and todo management tools are auto-approved.
|
|
@@ -772,6 +829,10 @@ type ConversationMetadata = {
|
|
|
772
829
|
promptTokens?: number;
|
|
773
830
|
completionTokens?: number;
|
|
774
831
|
contextWindow?: TokenUsage;
|
|
832
|
+
requestCount?: number;
|
|
833
|
+
toolCallCount?: number;
|
|
834
|
+
totalTimeMs?: number;
|
|
835
|
+
totalPrice?: number;
|
|
775
836
|
};
|
|
776
837
|
type Conversation = {
|
|
777
838
|
messages: Message[];
|
|
@@ -787,6 +848,14 @@ declare class ConversationStore {
|
|
|
787
848
|
appendMessages(conversationId: string, messages: Message[]): Promise<void>;
|
|
788
849
|
updateMetadata(conversationId: string, updates: Partial<ConversationMetadata>): Promise<void>;
|
|
789
850
|
incrementTokens(conversationId: string, tokenUsage: TokenUsage): Promise<void>;
|
|
851
|
+
recordRequestMetrics(conversationId: string, metrics: {
|
|
852
|
+
promptTokens?: number;
|
|
853
|
+
completionTokens?: number;
|
|
854
|
+
totalTokens?: number;
|
|
855
|
+
toolCalls?: number;
|
|
856
|
+
responseTimeMs?: number;
|
|
857
|
+
cost?: number;
|
|
858
|
+
}): Promise<ConversationMetadata>;
|
|
790
859
|
updateTopic(conversationId: string, topic: string): Promise<void>;
|
|
791
860
|
deleteConversation(conversationId: string): Promise<void>;
|
|
792
861
|
listConversations(): Promise<{
|
|
@@ -805,6 +874,30 @@ declare class ConversationContext {
|
|
|
805
874
|
private slugify;
|
|
806
875
|
}
|
|
807
876
|
|
|
877
|
+
declare const createEmptySnapshot: () => MetricsSnapshot;
|
|
878
|
+
declare class NoopMetricsPort implements MetricsPort {
|
|
879
|
+
recordLLMCall(_usage: UsageData, _cost?: number): void;
|
|
880
|
+
recordToolCall(): void;
|
|
881
|
+
recordRequestComplete(_responseTimeMs: number): void;
|
|
882
|
+
setContextWindow(_limit: number, _usage: number): void;
|
|
883
|
+
reset(): void;
|
|
884
|
+
getSnapshot(): MetricsSnapshot;
|
|
885
|
+
}
|
|
886
|
+
type MetricsChangeHandler = (snapshot: MetricsSnapshot) => void;
|
|
887
|
+
declare class InMemoryMetricsPort implements MetricsPort {
|
|
888
|
+
private snapshot;
|
|
889
|
+
private onChange?;
|
|
890
|
+
constructor(onChange?: MetricsChangeHandler);
|
|
891
|
+
private emit;
|
|
892
|
+
recordLLMCall(usage: UsageData, cost?: number): void;
|
|
893
|
+
recordToolCall(): void;
|
|
894
|
+
recordRequestComplete(responseTimeMs: number): void;
|
|
895
|
+
setContextWindow(limit: number, usage: number): void;
|
|
896
|
+
reset(): void;
|
|
897
|
+
getSnapshot(): MetricsSnapshot;
|
|
898
|
+
setOnChange(fn: MetricsChangeHandler): void;
|
|
899
|
+
}
|
|
900
|
+
|
|
808
901
|
declare class SimpleId implements IdGenerator$1 {
|
|
809
902
|
uuid(): string;
|
|
810
903
|
}
|
|
@@ -1174,7 +1267,7 @@ declare abstract class BaseLLM implements LLMPort {
|
|
|
1174
1267
|
enablePromptCaching?: boolean;
|
|
1175
1268
|
});
|
|
1176
1269
|
protected abstract createTransport(): HttpTransport;
|
|
1177
|
-
|
|
1270
|
+
protected getTransport(): HttpTransport;
|
|
1178
1271
|
protected applyCacheControl(params: CompletionParams): CompletionParams;
|
|
1179
1272
|
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1180
1273
|
streamCompletion(params: CompletionParams, handlers?: {
|
|
@@ -1184,6 +1277,21 @@ declare abstract class BaseLLM implements LLMPort {
|
|
|
1184
1277
|
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1185
1278
|
}
|
|
1186
1279
|
|
|
1280
|
+
type ModelLimits = {
|
|
1281
|
+
contextWindow: number;
|
|
1282
|
+
maxOutput?: number;
|
|
1283
|
+
};
|
|
1284
|
+
type ModelInfo = {
|
|
1285
|
+
id: string;
|
|
1286
|
+
name?: string;
|
|
1287
|
+
limits?: ModelLimits;
|
|
1288
|
+
[key: string]: unknown;
|
|
1289
|
+
};
|
|
1290
|
+
type RawModelResponse = Record<string, unknown>;
|
|
1291
|
+
declare function normalizeModelLimits(provider: string, model: RawModelResponse): ModelLimits | null;
|
|
1292
|
+
declare function getFallbackLimits(provider: string, model: string): ModelLimits | null;
|
|
1293
|
+
declare function normalizeModelInfo(provider: string, model: RawModelResponse): ModelInfo;
|
|
1294
|
+
|
|
1187
1295
|
type GithubOptions = {
|
|
1188
1296
|
apiKey?: string;
|
|
1189
1297
|
accessToken?: string;
|
|
@@ -1194,6 +1302,14 @@ declare class GithubLLM extends BaseLLM implements LLMPort {
|
|
|
1194
1302
|
private readonly opts;
|
|
1195
1303
|
constructor(opts?: GithubOptions);
|
|
1196
1304
|
protected createTransport(): GithubAuthTransport;
|
|
1305
|
+
getModels(signal?: AbortSignal): Promise<ModelInfo[]>;
|
|
1306
|
+
private handleError;
|
|
1307
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1308
|
+
streamCompletion(params: CompletionParams, handlers?: {
|
|
1309
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
1310
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
1311
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
1312
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1197
1313
|
}
|
|
1198
1314
|
|
|
1199
1315
|
type AnthropicAISDKOptions = {
|
|
@@ -1248,6 +1364,7 @@ interface LLMOptions {
|
|
|
1248
1364
|
enablePromptCaching?: boolean;
|
|
1249
1365
|
includeUsage?: boolean;
|
|
1250
1366
|
version?: string;
|
|
1367
|
+
providerName?: string;
|
|
1251
1368
|
}
|
|
1252
1369
|
interface CustomProviderDefinition {
|
|
1253
1370
|
type?: 'openai-compat' | 'anthropic';
|
|
@@ -1348,4 +1465,4 @@ declare function resolveBackspaces(s: string): string;
|
|
|
1348
1465
|
declare function stripAnsiAndControls(s: string): string;
|
|
1349
1466
|
declare function canonicalizeTerminalPaste(raw: string): string;
|
|
1350
1467
|
|
|
1351
|
-
export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignParams, BashTool, type CompleteAgent, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, ErrorReason, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, NoopReminders, type OrchestratorAwareToolPort, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UserAttachment, type UserMessagePayload, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, createLLM, generateFolderTree, getAvailableProviders, loadMCPConfig, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels };
|
|
1468
|
+
export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignParams, BashTool, type CompleteAgent, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, ErrorReason, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, InMemoryMetricsPort, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, type MetricsChangeHandler, type MetricsPort, type MetricsSnapshot, type ModelInfo, type ModelLimits, NoopMetricsPort, NoopReminders, type OrchestratorAwareToolPort, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UsageData, type UserAttachment, type UserMessagePayload, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, createEmptySnapshot, createLLM, generateFolderTree, getAvailableProviders, getFallbackLimits, loadMCPConfig, normalizeModelInfo, normalizeModelLimits, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels };
|