@tuttiai/core 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 CHANGED
@@ -1,5 +1,18 @@
1
- import { TuttiEventType, TuttiEvent, ScoreConfig, AgentResult, Session, LLMProvider, SessionStore, AgentConfig, ChatMessage, Voice, Permission, BudgetConfig, ChatRequest, ChatResponse } from '@tuttiai/types';
2
- export { AgentConfig, AgentResult, BudgetConfig, ChatMessage, ChatRequest, ChatResponse, ContentBlock, LLMProvider, Permission, ScoreConfig, Session, SessionStore, StopReason, TextBlock, TokenUsage, Tool, ToolContext, ToolDefinition, ToolResult, ToolResultBlock, ToolUseBlock, TuttiEvent, TuttiEventHandler, TuttiEventType, Voice, VoiceContext } from '@tuttiai/types';
1
+ import pino from 'pino';
2
+ import { TelemetryConfig, TuttiEventType, TuttiEvent, ScoreConfig, AgentResult, Session, LLMProvider, SessionStore, AgentConfig, ChatMessage, Voice, Permission, BudgetConfig, ChatRequest, ChatResponse } from '@tuttiai/types';
3
+ export { 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 } from '@tuttiai/types';
4
+
5
+ declare const createLogger: (name: string) => pino.Logger<never, boolean>;
6
+ declare const logger: pino.Logger<never, boolean>;
7
+
8
+ declare const TuttiTracer: {
9
+ agentRun<T>(agentName: string, sessionId: string, fn: () => Promise<T>): Promise<T>;
10
+ llmCall<T>(model: string, fn: () => Promise<T>): Promise<T>;
11
+ toolCall<T>(toolName: string, fn: () => Promise<T>): Promise<T>;
12
+ };
13
+
14
+ declare function initTelemetry(config: TelemetryConfig): void;
15
+ declare function shutdownTelemetry(): Promise<void>;
3
16
 
4
17
  declare class EventBus {
5
18
  private listeners;
@@ -14,12 +27,46 @@ declare class EventBus {
14
27
  onAny(handler: (event: TuttiEvent) => void): () => void;
15
28
  }
16
29
 
30
+ /**
31
+ * Semantic (long-term) memory — facts agents remember across sessions.
32
+ *
33
+ * Session memory = conversation history within a session.
34
+ * Semantic memory = persistent facts that survive across sessions.
35
+ *
36
+ * Example: a user tells the coder agent "I prefer 2-space indentation".
37
+ * Next session, the agent already knows this preference.
38
+ */
39
+ interface MemoryEntry {
40
+ id: string;
41
+ agent_name: string;
42
+ content: string;
43
+ metadata: Record<string, unknown>;
44
+ created_at: Date;
45
+ }
46
+ interface SemanticMemoryStore {
47
+ /** Store a new memory entry. Returns the entry with generated id and timestamp. */
48
+ add(entry: Omit<MemoryEntry, "id" | "created_at">): Promise<MemoryEntry>;
49
+ /** Search for relevant memories by keyword overlap. Returns top N by relevance. */
50
+ search(query: string, agent_name: string, limit?: number): Promise<MemoryEntry[]>;
51
+ /** Delete a single memory by ID. */
52
+ delete(id: string): Promise<void>;
53
+ /** Clear all memories for a specific agent. */
54
+ clear(agent_name: string): Promise<void>;
55
+ }
56
+
17
57
  declare class TuttiRuntime {
18
58
  readonly events: EventBus;
59
+ readonly semanticMemory: SemanticMemoryStore;
19
60
  private _sessions;
20
61
  private _runner;
21
62
  private _score;
22
63
  constructor(score: ScoreConfig);
64
+ /**
65
+ * Create a runtime with async initialization (required for Postgres).
66
+ * Prefer this over `new TuttiRuntime()` when using a database-backed store.
67
+ */
68
+ static create(score: ScoreConfig): Promise<TuttiRuntime>;
69
+ private static createStore;
23
70
  /** The score configuration this runtime was created with. */
24
71
  get score(): ScoreConfig;
25
72
  /**
@@ -35,7 +82,8 @@ declare class AgentRunner {
35
82
  private provider;
36
83
  private events;
37
84
  private sessions;
38
- constructor(provider: LLMProvider, events: EventBus, sessions: SessionStore);
85
+ private semanticMemory?;
86
+ constructor(provider: LLMProvider, events: EventBus, sessions: SessionStore, semanticMemory?: SemanticMemoryStore | undefined);
39
87
  run(agent: AgentConfig, input: string, session_id?: string): Promise<AgentResult>;
40
88
  private executeWithTimeout;
41
89
  private executeTool;
@@ -70,6 +118,41 @@ declare class InMemorySessionStore implements SessionStore {
70
118
  update(id: string, messages: ChatMessage[]): void;
71
119
  }
72
120
 
121
+ declare class PostgresSessionStore implements SessionStore {
122
+ private pool;
123
+ constructor(connectionString: string);
124
+ /**
125
+ * Create the tutti_sessions table if it doesn't exist.
126
+ * Call this once before using the store.
127
+ */
128
+ initialize(): Promise<void>;
129
+ create(agent_name: string): Session;
130
+ get(_id: string): Session | undefined;
131
+ /**
132
+ * Async version of get() that queries Postgres directly.
133
+ * Use this when you need to load a session from the database.
134
+ */
135
+ getAsync(id: string): Promise<Session | undefined>;
136
+ update(id: string, messages: ChatMessage[]): void;
137
+ /** Close the connection pool. Call on shutdown. */
138
+ close(): Promise<void>;
139
+ }
140
+
141
+ /**
142
+ * In-memory semantic memory store using keyword overlap scoring.
143
+ *
144
+ * search() tokenises both the query and each stored entry into words,
145
+ * then scores by the number of overlapping tokens. No embeddings
146
+ * needed — simple and predictable for v1.
147
+ */
148
+ declare class InMemorySemanticStore implements SemanticMemoryStore {
149
+ private entries;
150
+ add(entry: Omit<MemoryEntry, "id" | "created_at">): Promise<MemoryEntry>;
151
+ search(query: string, agent_name: string, limit?: number): Promise<MemoryEntry[]>;
152
+ delete(id: string): Promise<void>;
153
+ clear(agent_name: string): Promise<void>;
154
+ }
155
+
73
156
  declare class ScoreLoader {
74
157
  /**
75
158
  * Dynamically import a tutti.score.ts file and return its config.
@@ -156,4 +239,4 @@ declare class GeminiProvider implements LLMProvider {
156
239
  chat(request: ChatRequest): Promise<ChatResponse>;
157
240
  }
158
241
 
159
- export { AgentRouter, AgentRunner, AnthropicProvider, type AnthropicProviderOptions, EventBus, GeminiProvider, type GeminiProviderOptions, InMemorySessionStore, OpenAIProvider, type OpenAIProviderOptions, PermissionGuard, PromptGuard, ScoreLoader, SecretsManager, TokenBudget, TuttiRuntime, defineScore, validateScore };
242
+ 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 };