@tuttiai/core 0.7.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 +167 -4
- package/dist/index.js +745 -201
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,158 @@
|
|
|
1
|
+
import { TuttiHooks, TokenUsage, ScoreConfig, TelemetryConfig, TuttiEventType, TuttiEvent, AgentResult, Session, LLMProvider, SessionStore, AgentConfig, ChatMessage, Voice, Permission, BudgetConfig, ChatRequest, ChatResponse, StreamChunk } from '@tuttiai/types';
|
|
2
|
+
export { AgentConfig, AgentMemoryConfig, AgentResult, BudgetConfig, ChatMessage, ChatRequest, ChatResponse, ContentBlock, HookContext, LLMProvider, MemoryConfig, Permission, ScoreConfig, Session, SessionStore, StopReason, StreamChunk, TelemetryConfig, TextBlock, TokenUsage, Tool, ToolContext, ToolDefinition, ToolMemoryHelpers, ToolResult, ToolResultBlock, ToolUseBlock, TuttiEvent, TuttiEventHandler, TuttiEventType, TuttiHooks, Voice, VoiceContext } from '@tuttiai/types';
|
|
1
3
|
import pino from 'pino';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Typed error hierarchy for Tutti. All errors extend TuttiError.
|
|
7
|
+
*/
|
|
8
|
+
declare class TuttiError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly context: Record<string, unknown>;
|
|
11
|
+
constructor(code: string, message: string, context?: Record<string, unknown>);
|
|
12
|
+
}
|
|
13
|
+
declare class ScoreValidationError extends TuttiError {
|
|
14
|
+
constructor(message: string, context?: {
|
|
15
|
+
field?: string;
|
|
16
|
+
value?: unknown;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
declare class AgentNotFoundError extends TuttiError {
|
|
20
|
+
constructor(agentId: string, available: string[]);
|
|
21
|
+
}
|
|
22
|
+
declare class PermissionError extends TuttiError {
|
|
23
|
+
constructor(voice: string, required: string[], granted: string[]);
|
|
24
|
+
}
|
|
25
|
+
declare class BudgetExceededError extends TuttiError {
|
|
26
|
+
constructor(tokens: number, costUsd: number, limit: string);
|
|
27
|
+
}
|
|
28
|
+
declare class ToolTimeoutError extends TuttiError {
|
|
29
|
+
constructor(tool: string, timeoutMs: number);
|
|
30
|
+
}
|
|
31
|
+
declare class ProviderError extends TuttiError {
|
|
32
|
+
constructor(message: string, context?: {
|
|
33
|
+
provider: string;
|
|
34
|
+
status?: number;
|
|
35
|
+
} & Record<string, unknown>);
|
|
36
|
+
}
|
|
37
|
+
declare class AuthenticationError extends ProviderError {
|
|
38
|
+
constructor(provider: string);
|
|
39
|
+
}
|
|
40
|
+
declare class RateLimitError extends ProviderError {
|
|
41
|
+
readonly retryAfter?: number;
|
|
42
|
+
constructor(provider: string, retryAfter?: number);
|
|
43
|
+
}
|
|
44
|
+
declare class ContextWindowError extends ProviderError {
|
|
45
|
+
readonly maxTokens?: number;
|
|
46
|
+
constructor(provider: string, maxTokens?: number);
|
|
47
|
+
}
|
|
48
|
+
declare class VoiceError extends TuttiError {
|
|
49
|
+
constructor(message: string, context: {
|
|
50
|
+
voice: string;
|
|
51
|
+
tool?: string;
|
|
52
|
+
} & Record<string, unknown>);
|
|
53
|
+
}
|
|
54
|
+
declare class PathTraversalError extends VoiceError {
|
|
55
|
+
constructor(path: string);
|
|
56
|
+
}
|
|
57
|
+
declare class UrlValidationError extends VoiceError {
|
|
58
|
+
constructor(url: string);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Built-in hook factories for common patterns.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Logs all LLM calls and tool executions via a pino logger.
|
|
67
|
+
*/
|
|
68
|
+
declare function createLoggingHook(log: pino.Logger): TuttiHooks;
|
|
69
|
+
/**
|
|
70
|
+
* Caches tool results by tool name + input hash.
|
|
71
|
+
* The `store` is a simple Map or any get/set interface.
|
|
72
|
+
*/
|
|
73
|
+
declare function createCacheHook(store: {
|
|
74
|
+
get(key: string): string | undefined;
|
|
75
|
+
set(key: string, value: string): void;
|
|
76
|
+
}): TuttiHooks;
|
|
77
|
+
/**
|
|
78
|
+
* Blocks specific tool names from being called.
|
|
79
|
+
*/
|
|
80
|
+
declare function createBlocklistHook(blockedTools: string[]): TuttiHooks;
|
|
81
|
+
/**
|
|
82
|
+
* Blocks LLM calls once estimated cost exceeds the given USD limit.
|
|
83
|
+
* Tracks cost across the lifetime of the hook instance.
|
|
84
|
+
*/
|
|
85
|
+
declare function createMaxCostHook(maxUsd: number): TuttiHooks;
|
|
86
|
+
|
|
87
|
+
/** Evaluation framework types. */
|
|
88
|
+
|
|
89
|
+
interface EvalAssertion {
|
|
90
|
+
type: "contains" | "not_contains" | "matches_regex" | "tool_called" | "tool_not_called" | "turns_lte" | "cost_lte";
|
|
91
|
+
value: string | number;
|
|
92
|
+
description?: string;
|
|
93
|
+
}
|
|
94
|
+
interface EvalCase {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
agent_id: string;
|
|
98
|
+
input: string;
|
|
99
|
+
assertions: EvalAssertion[];
|
|
100
|
+
}
|
|
101
|
+
interface EvalSuite {
|
|
102
|
+
name: string;
|
|
103
|
+
cases: EvalCase[];
|
|
104
|
+
}
|
|
105
|
+
interface AssertionResult {
|
|
106
|
+
assertion: EvalAssertion;
|
|
107
|
+
passed: boolean;
|
|
108
|
+
actual: string | number;
|
|
109
|
+
}
|
|
110
|
+
interface EvalResult {
|
|
111
|
+
case_id: string;
|
|
112
|
+
case_name: string;
|
|
113
|
+
passed: boolean;
|
|
114
|
+
score: number;
|
|
115
|
+
output: string;
|
|
116
|
+
turns: number;
|
|
117
|
+
usage: TokenUsage;
|
|
118
|
+
cost_usd: number;
|
|
119
|
+
duration_ms: number;
|
|
120
|
+
assertions: AssertionResult[];
|
|
121
|
+
error?: string;
|
|
122
|
+
}
|
|
123
|
+
interface EvalSummary {
|
|
124
|
+
total: number;
|
|
125
|
+
passed: number;
|
|
126
|
+
failed: number;
|
|
127
|
+
avg_score: number;
|
|
128
|
+
total_cost_usd: number;
|
|
129
|
+
total_duration_ms: number;
|
|
130
|
+
}
|
|
131
|
+
interface EvalReport {
|
|
132
|
+
suite_name: string;
|
|
133
|
+
results: EvalResult[];
|
|
134
|
+
summary: EvalSummary;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Evaluation runner — executes test suites against a score. */
|
|
138
|
+
|
|
139
|
+
declare class EvalRunner {
|
|
140
|
+
private runtime;
|
|
141
|
+
constructor(score: ScoreConfig);
|
|
142
|
+
run(suite: EvalSuite): Promise<EvalReport>;
|
|
143
|
+
private runCase;
|
|
144
|
+
private checkAssertion;
|
|
145
|
+
private summarize;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Evaluation report formatting — table, JSON, Markdown. */
|
|
149
|
+
|
|
150
|
+
/** Print a formatted results table to stdout. */
|
|
151
|
+
declare function printTable(report: EvalReport): void;
|
|
152
|
+
/** Convert report to a plain JSON object for storage or CI. */
|
|
153
|
+
declare function toJSON(report: EvalReport): string;
|
|
154
|
+
/** Convert report to a GitHub-friendly markdown table. */
|
|
155
|
+
declare function toMarkdown(report: EvalReport): string;
|
|
4
156
|
|
|
5
157
|
declare const createLogger: (name: string) => pino.Logger<never, boolean>;
|
|
6
158
|
declare const logger: pino.Logger<never, boolean>;
|
|
@@ -74,6 +226,11 @@ declare class TuttiRuntime {
|
|
|
74
226
|
* Optionally pass a session_id to continue a conversation.
|
|
75
227
|
*/
|
|
76
228
|
run(agent_name: string, input: string, session_id?: string): Promise<AgentResult>;
|
|
229
|
+
/**
|
|
230
|
+
* Provide an answer to a pending human-in-the-loop request.
|
|
231
|
+
* Call this when a `hitl:requested` event fires to resume the agent.
|
|
232
|
+
*/
|
|
233
|
+
answer(sessionId: string, answer: string): void;
|
|
77
234
|
/** Retrieve an existing session. */
|
|
78
235
|
getSession(id: string): Session | undefined;
|
|
79
236
|
}
|
|
@@ -83,10 +240,16 @@ declare class AgentRunner {
|
|
|
83
240
|
private events;
|
|
84
241
|
private sessions;
|
|
85
242
|
private semanticMemory?;
|
|
86
|
-
|
|
243
|
+
private globalHooks?;
|
|
244
|
+
private pendingHitl;
|
|
245
|
+
constructor(provider: LLMProvider, events: EventBus, sessions: SessionStore, semanticMemory?: SemanticMemoryStore | undefined, globalHooks?: TuttiHooks | undefined);
|
|
246
|
+
private safeHook;
|
|
247
|
+
/** Resolve a pending human-in-the-loop request for a session. */
|
|
248
|
+
answer(sessionId: string, answer: string): void;
|
|
87
249
|
run(agent: AgentConfig, input: string, session_id?: string): Promise<AgentResult>;
|
|
88
250
|
private executeWithTimeout;
|
|
89
251
|
private streamToResponse;
|
|
252
|
+
private createHitlTool;
|
|
90
253
|
private executeTool;
|
|
91
254
|
}
|
|
92
255
|
|
|
@@ -243,4 +406,4 @@ declare class GeminiProvider implements LLMProvider {
|
|
|
243
406
|
stream(request: ChatRequest): AsyncGenerator<StreamChunk>;
|
|
244
407
|
}
|
|
245
408
|
|
|
246
|
-
export { AgentRouter, AgentRunner, AnthropicProvider, type AnthropicProviderOptions, EventBus, GeminiProvider, type GeminiProviderOptions, InMemorySemanticStore, InMemorySessionStore, type MemoryEntry, OpenAIProvider, type OpenAIProviderOptions, PermissionGuard, PostgresSessionStore, PromptGuard, ScoreLoader, SecretsManager, type SemanticMemoryStore, TokenBudget, TuttiRuntime, TuttiTracer, createLogger, defineScore, initTelemetry, logger, shutdownTelemetry, validateScore };
|
|
409
|
+
export { AgentNotFoundError, AgentRouter, AgentRunner, AnthropicProvider, type AnthropicProviderOptions, AuthenticationError, BudgetExceededError, ContextWindowError, type EvalAssertion, type EvalCase, type EvalReport, type EvalResult, EvalRunner, type EvalSuite, type EvalSummary, EventBus, GeminiProvider, type GeminiProviderOptions, InMemorySemanticStore, InMemorySessionStore, type MemoryEntry, OpenAIProvider, type OpenAIProviderOptions, PathTraversalError, PermissionError, PermissionGuard, PostgresSessionStore, PromptGuard, ProviderError, RateLimitError, ScoreLoader, ScoreValidationError, SecretsManager, type SemanticMemoryStore, TokenBudget, ToolTimeoutError, TuttiError, TuttiRuntime, TuttiTracer, UrlValidationError, VoiceError, createBlocklistHook, createCacheHook, createLogger, createLoggingHook, createMaxCostHook, defineScore, toJSON as evalToJSON, toMarkdown as evalToMarkdown, initTelemetry, logger, printTable as printEvalTable, shutdownTelemetry, validateScore };
|