@maximem/synap-js-sdk 0.1.4 → 0.2.1

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/types/index.d.ts CHANGED
@@ -1,4 +1,28 @@
1
1
  export type LogLevel = 'debug' | 'error';
2
+ export type RetrievalMode = 'fast' | 'accurate';
3
+ export type IngestMode = 'fast' | 'long-range';
4
+ export type PromptStyle = 'structured' | 'narrative' | 'bullet_points';
5
+ export type ContextType =
6
+ | 'all'
7
+ | 'facts'
8
+ | 'preferences'
9
+ | 'episodes'
10
+ | 'emotions'
11
+ | 'temporal_events';
12
+ export type FlattenedContextType =
13
+ | 'fact'
14
+ | 'preference'
15
+ | 'episode'
16
+ | 'emotion'
17
+ | 'temporal_event';
18
+ export type DocumentType =
19
+ | 'ai-chat-conversation'
20
+ | 'document'
21
+ | 'email'
22
+ | 'pdf'
23
+ | 'image'
24
+ | 'audio'
25
+ | 'meeting-transcript';
2
26
 
3
27
  export interface BridgeLogHandler {
4
28
  (level: LogLevel, message: string): void;
@@ -31,30 +55,81 @@ export interface SynapClientOptions {
31
55
  }
32
56
 
33
57
  export interface ChatMessage {
34
- role?: string;
58
+ role?: 'user' | 'assistant';
35
59
  content: string;
60
+ metadata?: Record<string, string>;
36
61
  }
37
62
 
38
63
  export interface AddMemoryInput {
39
64
  userId: string;
65
+ customerId: string;
66
+ conversationId?: string;
67
+ sessionId?: string;
40
68
  messages: ChatMessage[];
69
+ mode?: IngestMode;
70
+ documentType?: DocumentType;
71
+ documentId?: string;
72
+ documentCreatedAt?: string;
73
+ metadata?: Record<string, unknown>;
41
74
  }
42
75
 
43
76
  export interface SearchMemoryInput {
44
77
  userId: string;
78
+ customerId?: string;
45
79
  query: string;
46
80
  maxResults?: number;
81
+ mode?: RetrievalMode;
82
+ conversationId?: string;
83
+ types?: ContextType[];
47
84
  }
48
85
 
49
86
  export interface GetMemoriesInput {
50
87
  userId: string;
88
+ customerId?: string;
89
+ mode?: RetrievalMode;
90
+ conversationId?: string;
91
+ maxResults?: number;
92
+ types?: ContextType[];
51
93
  }
52
94
 
53
95
  export interface DeleteMemoryInput {
54
96
  userId: string;
97
+ customerId?: string;
55
98
  memoryId?: string | null;
56
99
  }
57
100
 
101
+ export interface FetchUserContextInput {
102
+ userId: string;
103
+ customerId?: string;
104
+ conversationId?: string;
105
+ searchQuery?: string[];
106
+ maxResults?: number;
107
+ types?: ContextType[];
108
+ mode?: RetrievalMode;
109
+ }
110
+
111
+ export interface FetchCustomerContextInput {
112
+ customerId: string;
113
+ conversationId?: string;
114
+ searchQuery?: string[];
115
+ maxResults?: number;
116
+ types?: ContextType[];
117
+ mode?: RetrievalMode;
118
+ }
119
+
120
+ export interface FetchClientContextInput {
121
+ conversationId?: string;
122
+ searchQuery?: string[];
123
+ maxResults?: number;
124
+ types?: ContextType[];
125
+ mode?: RetrievalMode;
126
+ }
127
+
128
+ export interface GetContextForPromptInput {
129
+ conversationId: string;
130
+ style?: PromptStyle;
131
+ }
132
+
58
133
  export interface BridgeStepTiming {
59
134
  step: string;
60
135
  ms: number;
@@ -65,6 +140,115 @@ export interface BridgeTiming {
65
140
  steps: BridgeStepTiming[];
66
141
  }
67
142
 
143
+ export interface TemporalFields {
144
+ eventDate: string | null;
145
+ validUntil: string | null;
146
+ temporalCategory: string | null;
147
+ temporalConfidence: number;
148
+ }
149
+
150
+ export interface Fact extends TemporalFields {
151
+ id: string;
152
+ content: string;
153
+ confidence: number;
154
+ source: string;
155
+ extractedAt: string | null;
156
+ metadata: Record<string, unknown>;
157
+ }
158
+
159
+ export interface Preference extends TemporalFields {
160
+ id: string;
161
+ category: string;
162
+ content: string;
163
+ strength: number;
164
+ source: string;
165
+ extractedAt: string | null;
166
+ metadata: Record<string, unknown>;
167
+ }
168
+
169
+ export interface Episode extends TemporalFields {
170
+ id: string;
171
+ summary: string;
172
+ occurredAt: string | null;
173
+ significance: number;
174
+ participants: string[];
175
+ metadata: Record<string, unknown>;
176
+ }
177
+
178
+ export interface Emotion extends TemporalFields {
179
+ id: string;
180
+ emotionType: string;
181
+ intensity: number;
182
+ detectedAt: string | null;
183
+ context: string;
184
+ metadata: Record<string, unknown>;
185
+ }
186
+
187
+ export interface TemporalEvent {
188
+ id: string;
189
+ content: string;
190
+ eventDate: string | null;
191
+ validUntil: string | null;
192
+ temporalCategory: string;
193
+ temporalConfidence: number;
194
+ confidence: number;
195
+ source: string;
196
+ extractedAt: string | null;
197
+ metadata: Record<string, unknown>;
198
+ }
199
+
200
+ export interface RecentMessage {
201
+ role: string;
202
+ content: string;
203
+ timestamp: string | null;
204
+ messageId: string;
205
+ }
206
+
207
+ export interface ContextResponseMetadata {
208
+ correlationId: string;
209
+ ttlSeconds: number;
210
+ source: string;
211
+ retrievedAt: string | null;
212
+ compactionApplied: string | null;
213
+ }
214
+
215
+ export interface ConversationContext {
216
+ summary: string | null;
217
+ currentState: Record<string, unknown>;
218
+ keyExtractions: Record<string, Array<Record<string, unknown>>>;
219
+ recentTurns: Array<Record<string, unknown>>;
220
+ compactionId: string | null;
221
+ compactedAt: string | null;
222
+ conversationId: string | null;
223
+ }
224
+
225
+ export interface ContextResponse {
226
+ facts: Fact[];
227
+ preferences: Preference[];
228
+ episodes: Episode[];
229
+ emotions: Emotion[];
230
+ temporalEvents: TemporalEvent[];
231
+ conversationContext: ConversationContext | null;
232
+ metadata: ContextResponseMetadata;
233
+ rawResponse: Record<string, unknown>;
234
+ bridgeTiming?: BridgeTiming;
235
+ }
236
+
237
+ export interface ContextForPromptResult {
238
+ formattedContext: string | null;
239
+ available: boolean;
240
+ isStale: boolean;
241
+ compressionRatio: number | null;
242
+ validationScore: number | null;
243
+ compactionAgeSeconds: number | null;
244
+ qualityWarning: boolean;
245
+ recentMessages: RecentMessage[];
246
+ recentMessageCount: number;
247
+ compactedMessageCount: number;
248
+ totalMessageCount: number;
249
+ bridgeTiming?: BridgeTiming;
250
+ }
251
+
68
252
  export interface AddMemoryResult {
69
253
  success: boolean;
70
254
  latencyMs: number;
@@ -73,10 +257,13 @@ export interface AddMemoryResult {
73
257
  bridgeTiming?: BridgeTiming;
74
258
  }
75
259
 
76
- export interface SearchMemoryItem {
260
+ export interface SearchMemoryItem extends TemporalFields {
77
261
  id: string;
78
262
  memory: string;
79
263
  score?: number;
264
+ source?: string;
265
+ metadata: Record<string, unknown>;
266
+ contextType?: FlattenedContextType;
80
267
  }
81
268
 
82
269
  export interface SearchMemoryResult {
@@ -89,22 +276,23 @@ export interface SearchMemoryResult {
89
276
  bridgeTiming?: BridgeTiming;
90
277
  }
91
278
 
92
- export interface MemoryItem {
93
- id: string;
94
- memory: string;
95
- }
279
+ export interface MemoryItem extends SearchMemoryItem {}
96
280
 
97
281
  export interface GetMemoriesResult {
98
282
  success: boolean;
99
283
  latencyMs: number;
100
284
  memories: MemoryItem[];
101
285
  totalCount: number;
286
+ rawResponse: Record<string, unknown> | null;
287
+ source?: string;
102
288
  bridgeTiming?: BridgeTiming;
103
289
  }
104
290
 
105
291
  export interface DeleteMemoryResult {
106
292
  success: boolean;
293
+ latencyMs: number;
107
294
  deletedCount: number;
295
+ rawResponse: Record<string, unknown> | null;
108
296
  note?: string;
109
297
  bridgeTiming?: BridgeTiming;
110
298
  }
@@ -115,6 +303,10 @@ export class SynapClient {
115
303
  addMemory(input: AddMemoryInput): Promise<AddMemoryResult>;
116
304
  searchMemory(input: SearchMemoryInput): Promise<SearchMemoryResult>;
117
305
  getMemories(input: GetMemoriesInput): Promise<GetMemoriesResult>;
306
+ fetchUserContext(input: FetchUserContextInput): Promise<ContextResponse>;
307
+ fetchCustomerContext(input: FetchCustomerContextInput): Promise<ContextResponse>;
308
+ fetchClientContext(input?: FetchClientContextInput): Promise<ContextResponse>;
309
+ getContextForPrompt(input: GetContextForPromptInput): Promise<ContextForPromptResult>;
118
310
  deleteMemory(input: DeleteMemoryInput): Promise<DeleteMemoryResult>;
119
311
  shutdown(): Promise<void>;
120
312
  }
@@ -160,6 +352,33 @@ export interface SetupTypeScriptExtensionResult {
160
352
  wrapperCreated: boolean;
161
353
  }
162
354
 
355
+ // Error classes
356
+ export class SynapError extends Error {
357
+ correlationId: string | null;
358
+ constructor(message: string, correlationId?: string);
359
+ }
360
+ export class SynapTransientError extends SynapError {}
361
+ export class SynapPermanentError extends SynapError {}
362
+ export class NetworkTimeoutError extends SynapTransientError {}
363
+ export class RateLimitError extends SynapTransientError {
364
+ retryAfterSeconds: number | null;
365
+ constructor(message: string, retryAfterSeconds?: number, correlationId?: string);
366
+ }
367
+ export class ServiceUnavailableError extends SynapTransientError {}
368
+ export class AgentUnavailableError extends SynapTransientError {}
369
+ export class InvalidInputError extends SynapPermanentError {}
370
+ export class InvalidInstanceIdError extends InvalidInputError {}
371
+ export class InvalidConversationIdError extends InvalidInputError {}
372
+ export class AuthenticationError extends SynapPermanentError {}
373
+ export class CertificateExpiredError extends AuthenticationError {}
374
+ export class CertificateRenewalError extends AuthenticationError {}
375
+ export class BootstrapKeyInvalidError extends AuthenticationError {}
376
+ export class BootstrapError extends SynapPermanentError {}
377
+ export class ContextNotFoundError extends SynapPermanentError {}
378
+ export class SessionExpiredError extends SynapPermanentError {}
379
+ export class ListeningAlreadyActiveError extends SynapPermanentError {}
380
+ export class ListeningNotActiveError extends SynapPermanentError {}
381
+
163
382
  export function createClient(options?: SynapClientOptions): SynapClient;
164
383
  export function resolveInstanceId(explicitInstanceId?: string): string;
165
384
  export function setupPythonRuntime(