@tuttiai/core 0.3.0 → 0.5.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 CHANGED
@@ -1,5 +1,5 @@
1
- import { TuttiEventType, TuttiEvent, ScoreConfig, AgentResult, Session, LLMProvider, SessionStore, AgentConfig, ChatMessage, ChatRequest, ChatResponse } from '@tuttiai/types';
2
- export { AgentConfig, AgentResult, ChatMessage, ChatRequest, ChatResponse, ContentBlock, LLMProvider, ScoreConfig, Session, SessionStore, StopReason, TextBlock, TokenUsage, Tool, ToolContext, ToolDefinition, ToolResult, ToolResultBlock, ToolUseBlock, TuttiEvent, TuttiEventHandler, TuttiEventType, Voice, VoiceContext } from '@tuttiai/types';
1
+ import { TuttiEventType, TuttiEvent, ScoreConfig, AgentResult, Session, LLMProvider, SessionStore, AgentConfig, ChatMessage, Voice, Permission, BudgetConfig, ChatRequest, ChatResponse } from '@tuttiai/types';
2
+ export { AgentConfig, AgentMemoryConfig, AgentResult, BudgetConfig, ChatMessage, ChatRequest, ChatResponse, ContentBlock, LLMProvider, MemoryConfig, Permission, ScoreConfig, Session, SessionStore, StopReason, TextBlock, TokenUsage, Tool, ToolContext, ToolDefinition, ToolMemoryHelpers, ToolResult, ToolResultBlock, ToolUseBlock, TuttiEvent, TuttiEventHandler, TuttiEventType, Voice, VoiceContext } from '@tuttiai/types';
3
3
 
4
4
  declare class EventBus {
5
5
  private listeners;
@@ -14,12 +14,46 @@ declare class EventBus {
14
14
  onAny(handler: (event: TuttiEvent) => void): () => void;
15
15
  }
16
16
 
17
+ /**
18
+ * Semantic (long-term) memory — facts agents remember across sessions.
19
+ *
20
+ * Session memory = conversation history within a session.
21
+ * Semantic memory = persistent facts that survive across sessions.
22
+ *
23
+ * Example: a user tells the coder agent "I prefer 2-space indentation".
24
+ * Next session, the agent already knows this preference.
25
+ */
26
+ interface MemoryEntry {
27
+ id: string;
28
+ agent_name: string;
29
+ content: string;
30
+ metadata: Record<string, unknown>;
31
+ created_at: Date;
32
+ }
33
+ interface SemanticMemoryStore {
34
+ /** Store a new memory entry. Returns the entry with generated id and timestamp. */
35
+ add(entry: Omit<MemoryEntry, "id" | "created_at">): Promise<MemoryEntry>;
36
+ /** Search for relevant memories by keyword overlap. Returns top N by relevance. */
37
+ search(query: string, agent_name: string, limit?: number): Promise<MemoryEntry[]>;
38
+ /** Delete a single memory by ID. */
39
+ delete(id: string): Promise<void>;
40
+ /** Clear all memories for a specific agent. */
41
+ clear(agent_name: string): Promise<void>;
42
+ }
43
+
17
44
  declare class TuttiRuntime {
18
45
  readonly events: EventBus;
46
+ readonly semanticMemory: SemanticMemoryStore;
19
47
  private _sessions;
20
48
  private _runner;
21
49
  private _score;
22
50
  constructor(score: ScoreConfig);
51
+ /**
52
+ * Create a runtime with async initialization (required for Postgres).
53
+ * Prefer this over `new TuttiRuntime()` when using a database-backed store.
54
+ */
55
+ static create(score: ScoreConfig): Promise<TuttiRuntime>;
56
+ private static createStore;
23
57
  /** The score configuration this runtime was created with. */
24
58
  get score(): ScoreConfig;
25
59
  /**
@@ -35,8 +69,10 @@ declare class AgentRunner {
35
69
  private provider;
36
70
  private events;
37
71
  private sessions;
38
- constructor(provider: LLMProvider, events: EventBus, sessions: SessionStore);
72
+ private semanticMemory?;
73
+ constructor(provider: LLMProvider, events: EventBus, sessions: SessionStore, semanticMemory?: SemanticMemoryStore | undefined);
39
74
  run(agent: AgentConfig, input: string, session_id?: string): Promise<AgentResult>;
75
+ private executeWithTimeout;
40
76
  private executeTool;
41
77
  }
42
78
 
@@ -69,6 +105,41 @@ declare class InMemorySessionStore implements SessionStore {
69
105
  update(id: string, messages: ChatMessage[]): void;
70
106
  }
71
107
 
108
+ declare class PostgresSessionStore implements SessionStore {
109
+ private pool;
110
+ constructor(connectionString: string);
111
+ /**
112
+ * Create the tutti_sessions table if it doesn't exist.
113
+ * Call this once before using the store.
114
+ */
115
+ initialize(): Promise<void>;
116
+ create(agent_name: string): Session;
117
+ get(id: string): Session | undefined;
118
+ /**
119
+ * Async version of get() that queries Postgres directly.
120
+ * Use this when you need to load a session from the database.
121
+ */
122
+ getAsync(id: string): Promise<Session | undefined>;
123
+ update(id: string, messages: ChatMessage[]): void;
124
+ /** Close the connection pool. Call on shutdown. */
125
+ close(): Promise<void>;
126
+ }
127
+
128
+ /**
129
+ * In-memory semantic memory store using keyword overlap scoring.
130
+ *
131
+ * search() tokenises both the query and each stored entry into words,
132
+ * then scores by the number of overlapping tokens. No embeddings
133
+ * needed — simple and predictable for v1.
134
+ */
135
+ declare class InMemorySemanticStore implements SemanticMemoryStore {
136
+ private entries;
137
+ add(entry: Omit<MemoryEntry, "id" | "created_at">): Promise<MemoryEntry>;
138
+ search(query: string, agent_name: string, limit?: number): Promise<MemoryEntry[]>;
139
+ delete(id: string): Promise<void>;
140
+ clear(agent_name: string): Promise<void>;
141
+ }
142
+
72
143
  declare class ScoreLoader {
73
144
  /**
74
145
  * Dynamically import a tutti.score.ts file and return its config.
@@ -83,6 +154,47 @@ declare class ScoreLoader {
83
154
  */
84
155
  declare function defineScore(config: ScoreConfig): ScoreConfig;
85
156
 
157
+ declare class SecretsManager {
158
+ private static redactPatterns;
159
+ static redact(text: string): string;
160
+ static redactObject(obj: unknown): unknown;
161
+ static require(key: string): string;
162
+ static optional(key: string, fallback?: string): string | undefined;
163
+ }
164
+
165
+ declare class PermissionGuard {
166
+ static check(voice: Voice, granted: Permission[]): void;
167
+ static warn(voice: Voice): void;
168
+ }
169
+
170
+ declare class PromptGuard {
171
+ private static patterns;
172
+ static scan(content: string): {
173
+ safe: boolean;
174
+ found: string[];
175
+ };
176
+ static wrap(toolName: string, content: string): string;
177
+ }
178
+
179
+ declare class TokenBudget {
180
+ private config;
181
+ private model;
182
+ private used_input;
183
+ private used_output;
184
+ constructor(config: BudgetConfig, model: string);
185
+ add(input_tokens: number, output_tokens: number): void;
186
+ get total_tokens(): number;
187
+ get estimated_cost_usd(): number;
188
+ check(): "ok" | "warning" | "exceeded";
189
+ summary(): string;
190
+ }
191
+
192
+ /**
193
+ * Validate a loaded score config. Returns the config on success,
194
+ * throws a descriptive error on failure.
195
+ */
196
+ declare function validateScore(config: unknown): void;
197
+
86
198
  interface AnthropicProviderOptions {
87
199
  api_key?: string;
88
200
  }
@@ -114,4 +226,4 @@ declare class GeminiProvider implements LLMProvider {
114
226
  chat(request: ChatRequest): Promise<ChatResponse>;
115
227
  }
116
228
 
117
- export { AgentRouter, AgentRunner, AnthropicProvider, type AnthropicProviderOptions, EventBus, GeminiProvider, type GeminiProviderOptions, InMemorySessionStore, OpenAIProvider, type OpenAIProviderOptions, ScoreLoader, TuttiRuntime, defineScore };
229
+ 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, defineScore, validateScore };