@tuttiai/types 0.4.0 → 0.6.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 +68 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -47,8 +47,16 @@ interface TokenUsage {
|
|
|
47
47
|
input_tokens: number;
|
|
48
48
|
output_tokens: number;
|
|
49
49
|
}
|
|
50
|
+
interface StreamChunk {
|
|
51
|
+
type: "text" | "tool_use" | "usage";
|
|
52
|
+
text?: string;
|
|
53
|
+
tool?: Omit<ToolUseBlock, "type">;
|
|
54
|
+
usage?: TokenUsage;
|
|
55
|
+
stop_reason?: StopReason;
|
|
56
|
+
}
|
|
50
57
|
interface LLMProvider {
|
|
51
58
|
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
59
|
+
stream(request: ChatRequest): AsyncIterable<StreamChunk>;
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
/** Voice — a pluggable module that gives agents tools and capabilities. */
|
|
@@ -94,6 +102,38 @@ interface Voice {
|
|
|
94
102
|
teardown?(): Promise<void>;
|
|
95
103
|
}
|
|
96
104
|
|
|
105
|
+
/** Lifecycle hooks for agent runs, LLM calls, and tool executions. */
|
|
106
|
+
|
|
107
|
+
/** Context passed to every hook invocation. */
|
|
108
|
+
interface HookContext {
|
|
109
|
+
agent_name: string;
|
|
110
|
+
session_id: string;
|
|
111
|
+
turn: number;
|
|
112
|
+
metadata: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Lifecycle hooks for customizing agent behavior.
|
|
116
|
+
*
|
|
117
|
+
* Set on `ScoreConfig.hooks` (global) or `AgentConfig.hooks` (per-agent).
|
|
118
|
+
* Agent-level hooks merge with global hooks — both fire, agent-level first.
|
|
119
|
+
*
|
|
120
|
+
* Hook errors are caught and logged — they never crash the agent.
|
|
121
|
+
*/
|
|
122
|
+
interface TuttiHooks {
|
|
123
|
+
/** Called before each LLM call. Return a modified request to alter it. */
|
|
124
|
+
beforeLLMCall?: (ctx: HookContext, request: ChatRequest) => Promise<ChatRequest>;
|
|
125
|
+
/** Called after each LLM response. */
|
|
126
|
+
afterLLMCall?: (ctx: HookContext, response: ChatResponse) => Promise<void>;
|
|
127
|
+
/** Called before each tool execution. Return false to block the call, or modified input. */
|
|
128
|
+
beforeToolCall?: (ctx: HookContext, tool: string, input: unknown) => Promise<boolean | unknown>;
|
|
129
|
+
/** Called after each tool execution. Return a modified result. */
|
|
130
|
+
afterToolCall?: (ctx: HookContext, tool: string, result: ToolResult) => Promise<ToolResult>;
|
|
131
|
+
/** Called when an agent run starts (before the first turn). */
|
|
132
|
+
beforeAgentRun?: (ctx: HookContext) => Promise<void>;
|
|
133
|
+
/** Called when an agent run finishes (after the last turn). */
|
|
134
|
+
afterAgentRun?: (ctx: HookContext, result: AgentResult) => Promise<void>;
|
|
135
|
+
}
|
|
136
|
+
|
|
97
137
|
/** Agent configuration and result types. */
|
|
98
138
|
|
|
99
139
|
interface BudgetConfig {
|
|
@@ -123,10 +163,16 @@ interface AgentConfig {
|
|
|
123
163
|
budget?: BudgetConfig;
|
|
124
164
|
/** Semantic (long-term) memory configuration. */
|
|
125
165
|
semantic_memory?: AgentMemoryConfig;
|
|
166
|
+
/** Enable token-by-token streaming (default: false). */
|
|
167
|
+
streaming?: boolean;
|
|
168
|
+
/** Allow the agent to pause and ask the human for input (default: false). */
|
|
169
|
+
allow_human_input?: boolean;
|
|
126
170
|
/** Agent IDs this agent can delegate to via the orchestrator. */
|
|
127
171
|
delegates?: string[];
|
|
128
172
|
/** Role in the orchestration — orchestrator receives input first. */
|
|
129
173
|
role?: "orchestrator" | "specialist";
|
|
174
|
+
/** Agent-level lifecycle hooks — merged with global hooks from ScoreConfig. */
|
|
175
|
+
hooks?: TuttiHooks;
|
|
130
176
|
}
|
|
131
177
|
interface AgentResult {
|
|
132
178
|
session_id: string;
|
|
@@ -162,6 +208,8 @@ interface ScoreConfig {
|
|
|
162
208
|
memory?: MemoryConfig;
|
|
163
209
|
/** OpenTelemetry tracing configuration. */
|
|
164
210
|
telemetry?: TelemetryConfig;
|
|
211
|
+
/** Global lifecycle hooks — apply to all agents. */
|
|
212
|
+
hooks?: TuttiHooks;
|
|
165
213
|
}
|
|
166
214
|
|
|
167
215
|
/** Session types for conversation state management. */
|
|
@@ -247,10 +295,29 @@ type TuttiEvent = {
|
|
|
247
295
|
agent_name: string;
|
|
248
296
|
tokens: number;
|
|
249
297
|
cost_usd: number;
|
|
298
|
+
} | {
|
|
299
|
+
type: "token:stream";
|
|
300
|
+
agent_name: string;
|
|
301
|
+
text: string;
|
|
302
|
+
} | {
|
|
303
|
+
type: "hitl:requested";
|
|
304
|
+
agent_name: string;
|
|
305
|
+
session_id: string;
|
|
306
|
+
question: string;
|
|
307
|
+
options?: string[];
|
|
308
|
+
} | {
|
|
309
|
+
type: "hitl:answered";
|
|
310
|
+
agent_name: string;
|
|
311
|
+
session_id: string;
|
|
312
|
+
answer: string;
|
|
313
|
+
} | {
|
|
314
|
+
type: "hitl:timeout";
|
|
315
|
+
agent_name: string;
|
|
316
|
+
session_id: string;
|
|
250
317
|
};
|
|
251
318
|
type TuttiEventType = TuttiEvent["type"];
|
|
252
319
|
type TuttiEventHandler<T extends TuttiEventType = TuttiEventType> = (event: Extract<TuttiEvent, {
|
|
253
320
|
type: T;
|
|
254
321
|
}>) => void;
|
|
255
322
|
|
|
256
|
-
export type { AgentConfig, AgentMemoryConfig, AgentResult, BudgetConfig, ChatMessage, ChatRequest, ChatResponse, ContentBlock, LLMProvider, MemoryConfig, Permission, ScoreConfig, Session, SessionStore, StopReason, TelemetryConfig, TextBlock, TokenUsage, Tool, ToolContext, ToolDefinition, ToolMemoryHelpers, ToolResult, ToolResultBlock, ToolUseBlock, TuttiEvent, TuttiEventHandler, TuttiEventType, Voice, VoiceContext };
|
|
323
|
+
export type { 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 };
|