@neo4j-labs/agent-memory 0.3.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/CHANGELOG.md +79 -0
- package/LICENSE +190 -0
- package/README.md +154 -0
- package/dist/chunk-ASQMU7YC.js +58 -0
- package/dist/chunk-ASQMU7YC.js.map +1 -0
- package/dist/chunk-TGBKROHO.js +226 -0
- package/dist/chunk-TGBKROHO.js.map +1 -0
- package/dist/client-DSqbWQoa.d.ts +551 -0
- package/dist/index-qfRrdQNP.d.ts +42 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +1313 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/langchain.d.ts +56 -0
- package/dist/integrations/langchain.js +69 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/mastra.d.ts +56 -0
- package/dist/integrations/mastra.js +65 -0
- package/dist/integrations/mastra.js.map +1 -0
- package/dist/integrations/strands.d.ts +239 -0
- package/dist/integrations/strands.js +413 -0
- package/dist/integrations/strands.js.map +1 -0
- package/dist/mcp/index.d.ts +53 -0
- package/dist/mcp/index.js +256 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/middleware/vercel-ai.d.ts +86 -0
- package/dist/middleware/vercel-ai.js +107 -0
- package/dist/middleware/vercel-ai.js.map +1 -0
- package/dist/testing.d.ts +37 -0
- package/dist/testing.js +4 -0
- package/dist/testing.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { L as Logger, T as Transport } from './index-qfRrdQNP.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core type definitions for neo4j-agent-memory TypeScript client.
|
|
5
|
+
*
|
|
6
|
+
* Canonical types use camelCase. Wire format depends on transport:
|
|
7
|
+
* - BridgeTransport: snake_case JSON
|
|
8
|
+
* - RestTransport: camelCase JSON (matches the hosted service)
|
|
9
|
+
*
|
|
10
|
+
* Sub-clients translate between wire and canonical forms.
|
|
11
|
+
*/
|
|
12
|
+
type MessageRole = "user" | "assistant" | "system";
|
|
13
|
+
type ToolCallStatus = "pending" | "success" | "failure" | "error" | "timeout" | "cancelled";
|
|
14
|
+
interface Message {
|
|
15
|
+
id: string;
|
|
16
|
+
role: MessageRole;
|
|
17
|
+
content: string;
|
|
18
|
+
timestamp: string;
|
|
19
|
+
embedding?: number[];
|
|
20
|
+
metadata: Record<string, unknown>;
|
|
21
|
+
/** Hosted service: link back to the conversation. */
|
|
22
|
+
conversationId?: string;
|
|
23
|
+
}
|
|
24
|
+
interface Conversation {
|
|
25
|
+
id: string;
|
|
26
|
+
/** Bridge protocol session identifier (free-form string). */
|
|
27
|
+
sessionId: string;
|
|
28
|
+
messages: Message[];
|
|
29
|
+
/** Hosted service: message count when returned by list/metadata endpoints. */
|
|
30
|
+
messageCount?: number;
|
|
31
|
+
title?: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt?: string;
|
|
34
|
+
/** Hosted service: workspace owning this conversation. */
|
|
35
|
+
workspaceId?: string;
|
|
36
|
+
/** Hosted service: user the conversation belongs to. */
|
|
37
|
+
userId?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
interface SessionInfo {
|
|
41
|
+
sessionId: string;
|
|
42
|
+
messageCount: number;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
updatedAt?: string;
|
|
45
|
+
}
|
|
46
|
+
/** A 3-tier conversational context window — hosted service. */
|
|
47
|
+
interface ConversationContext {
|
|
48
|
+
reflections: Reflection[];
|
|
49
|
+
observations: Observation[];
|
|
50
|
+
recentMessages: Message[];
|
|
51
|
+
}
|
|
52
|
+
interface Observation {
|
|
53
|
+
id: string;
|
|
54
|
+
conversationId: string;
|
|
55
|
+
content: string;
|
|
56
|
+
windowStart?: string;
|
|
57
|
+
windowEnd?: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
}
|
|
60
|
+
interface Reflection {
|
|
61
|
+
id: string;
|
|
62
|
+
conversationId: string;
|
|
63
|
+
content: string;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
}
|
|
66
|
+
/** Bridge taxonomy. */
|
|
67
|
+
type EntityType = "PERSON" | "ORGANIZATION" | "LOCATION" | "EVENT" | "OBJECT";
|
|
68
|
+
/** Hosted-service entity taxonomy. */
|
|
69
|
+
type HostedEntityType = "person" | "organization" | "location" | "concept" | "tool" | "custom";
|
|
70
|
+
interface Entity {
|
|
71
|
+
id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
type: string;
|
|
74
|
+
subtype?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
embedding?: number[];
|
|
77
|
+
canonicalName?: string;
|
|
78
|
+
createdAt: string;
|
|
79
|
+
/** Hosted service. */
|
|
80
|
+
updatedAt?: string;
|
|
81
|
+
/** Hosted service: confidence score (0-1). */
|
|
82
|
+
confidence?: number;
|
|
83
|
+
/** Hosted service: which extraction stage produced the entity. */
|
|
84
|
+
sourceStage?: string;
|
|
85
|
+
/** Hosted service: relationships referenced by getEntity. */
|
|
86
|
+
relationships?: EntityRelationshipRef[];
|
|
87
|
+
}
|
|
88
|
+
interface EntityRelationshipRef {
|
|
89
|
+
id: string;
|
|
90
|
+
type: string;
|
|
91
|
+
targetId: string;
|
|
92
|
+
targetName?: string;
|
|
93
|
+
properties?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
interface EntityHistory {
|
|
96
|
+
entityId: string;
|
|
97
|
+
mentions: EntityMention[];
|
|
98
|
+
}
|
|
99
|
+
interface EntityMention {
|
|
100
|
+
conversationId: string;
|
|
101
|
+
messageId?: string;
|
|
102
|
+
content: string;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
}
|
|
105
|
+
interface EntityGraphNode {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string;
|
|
108
|
+
type: string;
|
|
109
|
+
}
|
|
110
|
+
interface EntityGraphEdge {
|
|
111
|
+
id: string;
|
|
112
|
+
source: string;
|
|
113
|
+
target: string;
|
|
114
|
+
type: string;
|
|
115
|
+
}
|
|
116
|
+
interface EntityGraph {
|
|
117
|
+
nodes: EntityGraphNode[];
|
|
118
|
+
edges: EntityGraphEdge[];
|
|
119
|
+
}
|
|
120
|
+
interface EntityFeedbackResult {
|
|
121
|
+
id: string;
|
|
122
|
+
updated: boolean;
|
|
123
|
+
}
|
|
124
|
+
interface EntityMergeResult {
|
|
125
|
+
sourceId: string;
|
|
126
|
+
targetId: string;
|
|
127
|
+
status: string;
|
|
128
|
+
}
|
|
129
|
+
interface Preference {
|
|
130
|
+
id: string;
|
|
131
|
+
category: string;
|
|
132
|
+
preference: string;
|
|
133
|
+
context?: string;
|
|
134
|
+
embedding?: number[];
|
|
135
|
+
}
|
|
136
|
+
interface Fact {
|
|
137
|
+
id: string;
|
|
138
|
+
subject: string;
|
|
139
|
+
predicate: string;
|
|
140
|
+
object: string;
|
|
141
|
+
embedding?: number[];
|
|
142
|
+
}
|
|
143
|
+
interface Relationship {
|
|
144
|
+
id: string;
|
|
145
|
+
sourceId: string;
|
|
146
|
+
targetId: string;
|
|
147
|
+
relationshipType: string;
|
|
148
|
+
properties: Record<string, unknown>;
|
|
149
|
+
}
|
|
150
|
+
interface ReasoningTrace {
|
|
151
|
+
id: string;
|
|
152
|
+
sessionId: string;
|
|
153
|
+
task: string;
|
|
154
|
+
steps: ReasoningStep[];
|
|
155
|
+
outcome?: string;
|
|
156
|
+
success?: boolean;
|
|
157
|
+
startedAt: string;
|
|
158
|
+
completedAt?: string;
|
|
159
|
+
}
|
|
160
|
+
interface ReasoningStep {
|
|
161
|
+
id: string;
|
|
162
|
+
traceId: string;
|
|
163
|
+
stepNumber: number;
|
|
164
|
+
thought?: string;
|
|
165
|
+
action?: string;
|
|
166
|
+
observation?: string;
|
|
167
|
+
toolCalls: ToolCall[];
|
|
168
|
+
}
|
|
169
|
+
interface ToolCall {
|
|
170
|
+
id: string;
|
|
171
|
+
/** Reasoning step this tool call hangs off (hosted service exposes this). */
|
|
172
|
+
stepId?: string;
|
|
173
|
+
toolName: string;
|
|
174
|
+
arguments: Record<string, unknown>;
|
|
175
|
+
result?: unknown;
|
|
176
|
+
status: ToolCallStatus;
|
|
177
|
+
durationMs?: number;
|
|
178
|
+
error?: string;
|
|
179
|
+
}
|
|
180
|
+
interface ToolStats {
|
|
181
|
+
name: string;
|
|
182
|
+
totalCalls: number;
|
|
183
|
+
successfulCalls: number;
|
|
184
|
+
failedCalls: number;
|
|
185
|
+
successRate: number;
|
|
186
|
+
avgDurationMs?: number;
|
|
187
|
+
}
|
|
188
|
+
/** Hosted-service flat reasoning step (per-conversation, no trace wrapper). */
|
|
189
|
+
interface AgentStep {
|
|
190
|
+
id: string;
|
|
191
|
+
conversationId: string;
|
|
192
|
+
reasoning: string;
|
|
193
|
+
actionTaken: string;
|
|
194
|
+
result?: string;
|
|
195
|
+
createdAt: string;
|
|
196
|
+
}
|
|
197
|
+
/** Hosted: detailed step with tool calls + influenced entities. */
|
|
198
|
+
interface AgentStepExplanation extends AgentStep {
|
|
199
|
+
toolCalls: ToolCall[];
|
|
200
|
+
influencedEntities: Entity[];
|
|
201
|
+
}
|
|
202
|
+
/** Hosted: flat reasoning trace (steps + tool calls under one conversation). */
|
|
203
|
+
interface ConversationTrace {
|
|
204
|
+
conversationId: string;
|
|
205
|
+
steps: AgentStep[];
|
|
206
|
+
toolCalls: ToolCall[];
|
|
207
|
+
}
|
|
208
|
+
/** Hosted: provenance of an entity's creation. */
|
|
209
|
+
interface EntityProvenance {
|
|
210
|
+
entityId: string;
|
|
211
|
+
steps: AgentStep[];
|
|
212
|
+
}
|
|
213
|
+
interface CypherResult {
|
|
214
|
+
columns: string[];
|
|
215
|
+
rows: unknown[][];
|
|
216
|
+
stats?: Record<string, unknown>;
|
|
217
|
+
}
|
|
218
|
+
interface ApiKey {
|
|
219
|
+
id: string;
|
|
220
|
+
label: string;
|
|
221
|
+
scopes: string[];
|
|
222
|
+
workspaceId: string;
|
|
223
|
+
createdAt: string;
|
|
224
|
+
expiresAt?: string;
|
|
225
|
+
/** Plaintext key — only present at creation time. */
|
|
226
|
+
key?: string;
|
|
227
|
+
}
|
|
228
|
+
interface AccessTokenPair {
|
|
229
|
+
accessToken: string;
|
|
230
|
+
refreshToken: string;
|
|
231
|
+
expiresIn: number;
|
|
232
|
+
}
|
|
233
|
+
type TransportMode = "auto" | "bridge" | "rest";
|
|
234
|
+
interface MemoryClientOptions {
|
|
235
|
+
/** Service base URL (bridge endpoint, or `https://.../v1` for REST). */
|
|
236
|
+
endpoint?: string;
|
|
237
|
+
/** API key for authentication. */
|
|
238
|
+
apiKey?: string;
|
|
239
|
+
/** Override transport selection. Default: "auto" (REST if endpoint contains /v1). */
|
|
240
|
+
transport?: TransportMode;
|
|
241
|
+
/** OAuth refresh-token-aware token provider. Overrides apiKey when supplied. */
|
|
242
|
+
tokenProvider?: () => string | Promise<string>;
|
|
243
|
+
/** Shared entity namespace for multi-agent collaboration. */
|
|
244
|
+
namespace?: string;
|
|
245
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
246
|
+
timeout?: number;
|
|
247
|
+
/** Additional headers to include in every request. */
|
|
248
|
+
headers?: Record<string, string>;
|
|
249
|
+
/**
|
|
250
|
+
* Optional logger invoked once per request / response / error. Useful for
|
|
251
|
+
* tracing requests in development. Caller controls log level by ignoring
|
|
252
|
+
* unwanted event kinds. See {@link LogEvent}.
|
|
253
|
+
*/
|
|
254
|
+
logger?: Logger;
|
|
255
|
+
}
|
|
256
|
+
interface AddMessageOptions {
|
|
257
|
+
metadata?: Record<string, unknown>;
|
|
258
|
+
}
|
|
259
|
+
interface GetConversationOptions {
|
|
260
|
+
limit?: number;
|
|
261
|
+
}
|
|
262
|
+
interface SearchMessagesOptions {
|
|
263
|
+
sessionId?: string;
|
|
264
|
+
limit?: number;
|
|
265
|
+
threshold?: number;
|
|
266
|
+
}
|
|
267
|
+
interface ListSessionsOptions {
|
|
268
|
+
limit?: number;
|
|
269
|
+
}
|
|
270
|
+
interface SearchEntitiesOptions {
|
|
271
|
+
limit?: number;
|
|
272
|
+
type?: string;
|
|
273
|
+
}
|
|
274
|
+
interface SearchPreferencesOptions {
|
|
275
|
+
category?: string;
|
|
276
|
+
limit?: number;
|
|
277
|
+
}
|
|
278
|
+
interface GetRelatedEntitiesOptions {
|
|
279
|
+
relationshipType?: string;
|
|
280
|
+
depth?: number;
|
|
281
|
+
}
|
|
282
|
+
interface ListTracesOptions {
|
|
283
|
+
sessionId?: string;
|
|
284
|
+
limit?: number;
|
|
285
|
+
}
|
|
286
|
+
interface RecordToolCallOptions {
|
|
287
|
+
result?: unknown;
|
|
288
|
+
status?: ToolCallStatus;
|
|
289
|
+
durationMs?: number;
|
|
290
|
+
error?: string;
|
|
291
|
+
}
|
|
292
|
+
interface CompleteTraceOptions {
|
|
293
|
+
outcome?: string;
|
|
294
|
+
success?: boolean;
|
|
295
|
+
}
|
|
296
|
+
interface AddRelationshipOptions {
|
|
297
|
+
properties?: Record<string, unknown>;
|
|
298
|
+
}
|
|
299
|
+
interface GetSimilarTracesOptions {
|
|
300
|
+
limit?: number;
|
|
301
|
+
successOnly?: boolean;
|
|
302
|
+
}
|
|
303
|
+
interface CreateConversationOptions {
|
|
304
|
+
userId: string;
|
|
305
|
+
metadata?: Record<string, unknown>;
|
|
306
|
+
}
|
|
307
|
+
interface ListConversationsOptions {
|
|
308
|
+
limit?: number;
|
|
309
|
+
userId?: string;
|
|
310
|
+
}
|
|
311
|
+
interface BulkMessageInput {
|
|
312
|
+
role: MessageRole;
|
|
313
|
+
content: string;
|
|
314
|
+
metadata?: Record<string, unknown>;
|
|
315
|
+
}
|
|
316
|
+
interface ListEntitiesOptions {
|
|
317
|
+
type?: HostedEntityType | string;
|
|
318
|
+
limit?: number;
|
|
319
|
+
}
|
|
320
|
+
interface UpdateEntityOptions {
|
|
321
|
+
name?: string;
|
|
322
|
+
description?: string;
|
|
323
|
+
}
|
|
324
|
+
interface SetEntityFeedbackOptions {
|
|
325
|
+
userScore: number;
|
|
326
|
+
confirmed: boolean;
|
|
327
|
+
}
|
|
328
|
+
interface RecordStepInput {
|
|
329
|
+
conversationId: string;
|
|
330
|
+
reasoning: string;
|
|
331
|
+
actionTaken: string;
|
|
332
|
+
result?: string;
|
|
333
|
+
}
|
|
334
|
+
interface CreateApiKeyInput {
|
|
335
|
+
label: string;
|
|
336
|
+
scopes: string[];
|
|
337
|
+
workspaceId: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Auth & API-key management — hosted service only.
|
|
342
|
+
*
|
|
343
|
+
* Static `nams_*` keys can be created, listed, revealed, and revoked. OAuth
|
|
344
|
+
* refresh-token rotation is also exposed for clients running PKCE flows.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
declare class AuthClient {
|
|
348
|
+
private readonly transport;
|
|
349
|
+
constructor(transport: Transport);
|
|
350
|
+
/** List API keys for a workspace (no plaintext). */
|
|
351
|
+
listApiKeys(workspaceId: string): Promise<ApiKey[]>;
|
|
352
|
+
/** Create a new API key. The plaintext value is returned only once. */
|
|
353
|
+
createApiKey(input: CreateApiKeyInput): Promise<ApiKey>;
|
|
354
|
+
/** Revoke (delete) an API key by id. */
|
|
355
|
+
revokeApiKey(keyId: string): Promise<void>;
|
|
356
|
+
/** Reveal the plaintext value of a stored API key. */
|
|
357
|
+
revealApiKey(keyId: string, workspaceId: string): Promise<ApiKey>;
|
|
358
|
+
/** Exchange a refresh token for a fresh access/refresh pair. */
|
|
359
|
+
refreshAccessToken(refreshToken: string): Promise<AccessTokenPair>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Long-term memory operations.
|
|
364
|
+
*
|
|
365
|
+
* Bridge methods (Silver tier) plus Volume 5 / hosted-native methods for
|
|
366
|
+
* entity feedback, history, merge-by-id, graph view, and provenance.
|
|
367
|
+
*/
|
|
368
|
+
|
|
369
|
+
declare class LongTermMemory {
|
|
370
|
+
private readonly transport;
|
|
371
|
+
constructor(transport: Transport);
|
|
372
|
+
addEntity(name: string, entityType: string, options?: {
|
|
373
|
+
description?: string;
|
|
374
|
+
}): Promise<Entity>;
|
|
375
|
+
addPreference(category: string, preference: string, options?: {
|
|
376
|
+
context?: string;
|
|
377
|
+
}): Promise<Preference>;
|
|
378
|
+
addFact(subject: string, predicate: string, obj: string): Promise<Fact>;
|
|
379
|
+
searchEntities(query: string, options?: SearchEntitiesOptions): Promise<Entity[]>;
|
|
380
|
+
searchPreferences(query: string, options?: SearchPreferencesOptions): Promise<Preference[]>;
|
|
381
|
+
getEntityByName(name: string): Promise<Entity | null>;
|
|
382
|
+
getRelatedEntities(entityId: string, options?: GetRelatedEntitiesOptions): Promise<Entity[]>;
|
|
383
|
+
addRelationship(sourceId: string, targetId: string, relationshipType: string, options?: AddRelationshipOptions): Promise<Relationship>;
|
|
384
|
+
mergeDuplicateEntities(sourceId: string, targetId: string, options?: {
|
|
385
|
+
canonicalName?: string;
|
|
386
|
+
}): Promise<Entity>;
|
|
387
|
+
/** List all entities, optionally filtered by entity type. */
|
|
388
|
+
listEntities(options?: ListEntitiesOptions): Promise<Entity[]>;
|
|
389
|
+
/** Fetch one entity (with relationships) by id. */
|
|
390
|
+
getEntity(entityId: string): Promise<Entity>;
|
|
391
|
+
/** Update an existing entity's name and/or description.
|
|
392
|
+
*
|
|
393
|
+
* The hosted PUT /v1/entities/{id} returns `{status: "updated"}` rather
|
|
394
|
+
* than the full entity, so when the response lacks an `id` we follow up
|
|
395
|
+
* with a GET to keep the SDK contract — "update returns the updated
|
|
396
|
+
* Entity". Bridge transports return the entity directly, so we tolerate
|
|
397
|
+
* both shapes.
|
|
398
|
+
*/
|
|
399
|
+
updateEntity(entityId: string, options: UpdateEntityOptions): Promise<Entity>;
|
|
400
|
+
/** Delete an entity and its relationships. */
|
|
401
|
+
deleteEntity(entityId: string): Promise<void>;
|
|
402
|
+
/** Score an entity 0-1 and optionally mark it human-confirmed. */
|
|
403
|
+
setEntityFeedback(entityId: string, options: SetEntityFeedbackOptions): Promise<EntityFeedbackResult>;
|
|
404
|
+
/** All cross-conversation mentions of this entity. */
|
|
405
|
+
getEntityHistory(entityId: string): Promise<EntityHistory>;
|
|
406
|
+
/** Merge `sourceId` into `targetId`, leaving a SAME_AS provenance link. */
|
|
407
|
+
mergeEntities(sourceId: string, targetId: string): Promise<EntityMergeResult>;
|
|
408
|
+
/** Full-graph view of all entities + edges. Pair with NVL for visualization. */
|
|
409
|
+
getEntityGraph(): Promise<EntityGraph>;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Cypher query console — read-only access to the underlying graph.
|
|
414
|
+
*
|
|
415
|
+
* Hosted service only: write operations are rejected with HTTP 400.
|
|
416
|
+
*/
|
|
417
|
+
|
|
418
|
+
declare class QueryConsole {
|
|
419
|
+
private readonly transport;
|
|
420
|
+
constructor(transport: Transport);
|
|
421
|
+
/**
|
|
422
|
+
* Execute a read-only Cypher query.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* const r = await client.query.cypher({
|
|
426
|
+
* cypher: "MATCH (e:Entity) RETURN e.name AS name LIMIT $n",
|
|
427
|
+
* params: { n: 10 },
|
|
428
|
+
* });
|
|
429
|
+
*/
|
|
430
|
+
cypher(input: {
|
|
431
|
+
cypher: string;
|
|
432
|
+
params?: Record<string, unknown>;
|
|
433
|
+
}): Promise<CypherResult>;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Reasoning memory operations.
|
|
438
|
+
*
|
|
439
|
+
* Bridge methods (Silver tier) wrap traces. Volume 5 / hosted-native methods
|
|
440
|
+
* are flatter — steps belong directly to a conversation, with explain &
|
|
441
|
+
* provenance views for the reasoning trail behind any entity.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
declare class ReasoningMemory {
|
|
445
|
+
private readonly transport;
|
|
446
|
+
constructor(transport: Transport);
|
|
447
|
+
startTrace(sessionId: string, task: string): Promise<ReasoningTrace>;
|
|
448
|
+
addStep(traceId: string, options?: {
|
|
449
|
+
thought?: string;
|
|
450
|
+
action?: string;
|
|
451
|
+
observation?: string;
|
|
452
|
+
}): Promise<ReasoningStep>;
|
|
453
|
+
recordToolCall(stepId: string, toolName: string, args: Record<string, unknown>, options?: RecordToolCallOptions): Promise<ToolCall>;
|
|
454
|
+
completeTrace(traceId: string, options?: CompleteTraceOptions): Promise<ReasoningTrace>;
|
|
455
|
+
getTraceWithSteps(traceId: string): Promise<ReasoningTrace | null>;
|
|
456
|
+
listTraces(options?: ListTracesOptions): Promise<ReasoningTrace[]>;
|
|
457
|
+
getToolStats(toolName?: string): Promise<ToolStats[]>;
|
|
458
|
+
getSimilarTraces(task: string, options?: GetSimilarTracesOptions): Promise<ReasoningTrace[]>;
|
|
459
|
+
/** Record one reasoning step under a conversation (hosted REACT model). */
|
|
460
|
+
recordStep(input: RecordStepInput): Promise<AgentStep>;
|
|
461
|
+
/** List all reasoning steps for one conversation. */
|
|
462
|
+
listSteps(conversationId: string): Promise<AgentStep[]>;
|
|
463
|
+
/** Detailed step explanation with tool calls and influenced entities. */
|
|
464
|
+
explainStep(stepId: string): Promise<AgentStepExplanation>;
|
|
465
|
+
/** Full reasoning trace for a conversation (steps + tool calls). */
|
|
466
|
+
getTraceByConversation(conversationId: string): Promise<ConversationTrace>;
|
|
467
|
+
/** All reasoning steps that influenced an entity's creation.
|
|
468
|
+
*
|
|
469
|
+
* Hosted REST returns the chain under `provenance`; bridge / older
|
|
470
|
+
* responses use `steps`. Accept either.
|
|
471
|
+
*/
|
|
472
|
+
getEntityProvenance(entityId: string): Promise<EntityProvenance>;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Short-term (conversational) memory operations.
|
|
477
|
+
*
|
|
478
|
+
* Bridge methods (Bronze tier) speak the TCK BaseAdapter contract.
|
|
479
|
+
* Hosted methods speak the Volume 5 / Platinum tier hosted service operations.
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
declare class ShortTermMemory {
|
|
483
|
+
private readonly transport;
|
|
484
|
+
constructor(transport: Transport);
|
|
485
|
+
addMessage(sessionId: string, role: MessageRole, content: string, options?: AddMessageOptions): Promise<Message>;
|
|
486
|
+
getConversation(sessionId: string, options?: GetConversationOptions): Promise<Conversation>;
|
|
487
|
+
searchMessages(query: string, options?: SearchMessagesOptions): Promise<Message[]>;
|
|
488
|
+
listSessions(options?: ListSessionsOptions): Promise<SessionInfo[]>;
|
|
489
|
+
deleteMessage(messageId: string): Promise<boolean>;
|
|
490
|
+
clearSession(sessionId: string): Promise<void>;
|
|
491
|
+
/** Create a new conversation (hosted service). */
|
|
492
|
+
createConversation(options: CreateConversationOptions): Promise<Conversation>;
|
|
493
|
+
/** List conversations the API key has access to. */
|
|
494
|
+
listConversations(options?: ListConversationsOptions): Promise<Conversation[]>;
|
|
495
|
+
/** Fetch conversation metadata (no messages). */
|
|
496
|
+
getConversationMetadata(conversationId: string): Promise<Conversation>;
|
|
497
|
+
/** Delete a conversation and all its messages. */
|
|
498
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
499
|
+
/**
|
|
500
|
+
* Three-tier conversational context (reflections + observations + recent
|
|
501
|
+
* messages). The richest input you can hand an LLM about a conversation.
|
|
502
|
+
*/
|
|
503
|
+
getContext(conversationId: string): Promise<ConversationContext>;
|
|
504
|
+
/** Bulk-add up to 100 messages in one request. */
|
|
505
|
+
bulkAddMessages(conversationId: string, messages: BulkMessageInput[]): Promise<Message[]>;
|
|
506
|
+
/** Auto-generated message-window summaries. */
|
|
507
|
+
getObservations(conversationId: string, options?: {
|
|
508
|
+
limit?: number;
|
|
509
|
+
}): Promise<Observation[]>;
|
|
510
|
+
/** Higher-level reflections derived from observations. */
|
|
511
|
+
getReflections(conversationId: string): Promise<Reflection[]>;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* MemoryClient — root entry point for all memory operations.
|
|
516
|
+
*
|
|
517
|
+
* Zero-config form (Node, Bun, Deno):
|
|
518
|
+
*
|
|
519
|
+
* const client = new MemoryClient();
|
|
520
|
+
*
|
|
521
|
+
* defaults the endpoint to https://memory.neo4jlabs.com/v1 and reads
|
|
522
|
+
* MEMORY_API_KEY from the environment.
|
|
523
|
+
*
|
|
524
|
+
* Edge runtimes (Cloudflare Workers, Vercel Edge) read env from the request
|
|
525
|
+
* handler scope, not module init, so pass apiKey explicitly:
|
|
526
|
+
*
|
|
527
|
+
* const client = new MemoryClient({ apiKey: env.MEMORY_API_KEY });
|
|
528
|
+
*
|
|
529
|
+
* The first request triggers the auth probe automatically; calling
|
|
530
|
+
* `connect()` upfront is supported but optional.
|
|
531
|
+
*/
|
|
532
|
+
|
|
533
|
+
declare class MemoryClient {
|
|
534
|
+
/** Short-term (conversational) memory operations. */
|
|
535
|
+
readonly shortTerm: ShortTermMemory;
|
|
536
|
+
/** Long-term (entity / preference / fact / graph) memory operations. */
|
|
537
|
+
readonly longTerm: LongTermMemory;
|
|
538
|
+
/** Reasoning (trace / step / tool call / provenance) memory operations. */
|
|
539
|
+
readonly reasoning: ReasoningMemory;
|
|
540
|
+
/** Read-only Cypher query console (hosted service only). */
|
|
541
|
+
readonly query: QueryConsole;
|
|
542
|
+
/** API-key & OAuth management (hosted service only). */
|
|
543
|
+
readonly auth: AuthClient;
|
|
544
|
+
private readonly transport;
|
|
545
|
+
constructor(options?: MemoryClientOptions);
|
|
546
|
+
constructor(transport: Transport);
|
|
547
|
+
connect(): Promise<void>;
|
|
548
|
+
close(): Promise<void>;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export { type SessionInfo as $, type AccessTokenPair as A, type BulkMessageInput as B, type CompleteTraceOptions as C, type ListTracesOptions as D, type Entity as E, type Fact as F, type GetConversationOptions as G, type HostedEntityType as H, LongTermMemory as I, type MemoryClientOptions as J, type Message as K, type ListConversationsOptions as L, MemoryClient as M, type MessageRole as N, type Observation as O, type Preference as P, QueryConsole as Q, ReasoningMemory as R, type ReasoningStep as S, type ReasoningTrace as T, type RecordStepInput as U, type RecordToolCallOptions as V, type Reflection as W, type Relationship as X, type SearchEntitiesOptions as Y, type SearchMessagesOptions as Z, type SearchPreferencesOptions as _, type AddMessageOptions as a, type SetEntityFeedbackOptions as a0, ShortTermMemory as a1, type ToolCall as a2, type ToolCallStatus as a3, type ToolStats as a4, type TransportMode as a5, type UpdateEntityOptions as a6, type AddRelationshipOptions as b, type AgentStep as c, type AgentStepExplanation as d, type ApiKey as e, AuthClient as f, type Conversation as g, type ConversationContext as h, type ConversationTrace as i, type CreateApiKeyInput as j, type CreateConversationOptions as k, type CypherResult as l, type EntityFeedbackResult as m, type EntityGraph as n, type EntityGraphEdge as o, type EntityGraphNode as p, type EntityHistory as q, type EntityMention as r, type EntityMergeResult as s, type EntityProvenance as t, type EntityRelationshipRef as u, type EntityType as v, type GetRelatedEntitiesOptions as w, type GetSimilarTracesOptions as x, type ListEntitiesOptions as y, type ListSessionsOptions as z };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Single event emitted to the user-supplied logger. */
|
|
2
|
+
type LogEvent = {
|
|
3
|
+
kind: "request";
|
|
4
|
+
method: string;
|
|
5
|
+
url: string;
|
|
6
|
+
httpMethod?: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "response";
|
|
9
|
+
method: string;
|
|
10
|
+
url: string;
|
|
11
|
+
status: number;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
durationMs: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "error";
|
|
16
|
+
method: string;
|
|
17
|
+
url: string;
|
|
18
|
+
status?: number;
|
|
19
|
+
requestId?: string;
|
|
20
|
+
durationMs: number;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
type Logger = (event: LogEvent) => void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Transport abstraction layer.
|
|
27
|
+
*
|
|
28
|
+
* RestTransport speaks the hosted REST API at https://memory.neo4jlabs.com/v1
|
|
29
|
+
* and is the transport every application should use. BridgeTransport speaks
|
|
30
|
+
* the TCK bridge protocol and is exposed via the `./testing` subpath for
|
|
31
|
+
* conformance testing only.
|
|
32
|
+
*/
|
|
33
|
+
interface Transport {
|
|
34
|
+
/** Send a request to the backend and return the parsed response. */
|
|
35
|
+
request<T>(method: string, params: Record<string, unknown>): Promise<T>;
|
|
36
|
+
/** Establish the connection. */
|
|
37
|
+
connect(): Promise<void>;
|
|
38
|
+
/** Close the connection and release resources. */
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type { Logger as L, Transport as T, LogEvent as a };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export { A as AccessTokenPair, a as AddMessageOptions, b as AddRelationshipOptions, c as AgentStep, d as AgentStepExplanation, e as ApiKey, f as AuthClient, B as BulkMessageInput, C as CompleteTraceOptions, g as Conversation, h as ConversationContext, i as ConversationTrace, j as CreateApiKeyInput, k as CreateConversationOptions, l as CypherResult, E as Entity, m as EntityFeedbackResult, n as EntityGraph, o as EntityGraphEdge, p as EntityGraphNode, q as EntityHistory, r as EntityMention, s as EntityMergeResult, t as EntityProvenance, u as EntityRelationshipRef, v as EntityType, F as Fact, G as GetConversationOptions, w as GetRelatedEntitiesOptions, x as GetSimilarTracesOptions, H as HostedEntityType, L as ListConversationsOptions, y as ListEntitiesOptions, z as ListSessionsOptions, D as ListTracesOptions, I as LongTermMemory, M as MemoryClient, J as MemoryClientOptions, K as Message, N as MessageRole, O as Observation, P as Preference, Q as QueryConsole, R as ReasoningMemory, S as ReasoningStep, T as ReasoningTrace, U as RecordStepInput, V as RecordToolCallOptions, W as Reflection, X as Relationship, Y as SearchEntitiesOptions, Z as SearchMessagesOptions, _ as SearchPreferencesOptions, $ as SessionInfo, a0 as SetEntityFeedbackOptions, a1 as ShortTermMemory, a2 as ToolCall, a3 as ToolCallStatus, a4 as ToolStats, a5 as TransportMode, a6 as UpdateEntityOptions } from './client-DSqbWQoa.js';
|
|
2
|
+
import { T as Transport, L as Logger } from './index-qfRrdQNP.js';
|
|
3
|
+
export { a as LogEvent } from './index-qfRrdQNP.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* RestTransport — talks to the hosted Neo4j Agent Memory Service REST API.
|
|
7
|
+
*
|
|
8
|
+
* Endpoint should be the v1 root, e.g. `https://memory.neo4jlabs.com/v1`.
|
|
9
|
+
* Routes the bridge-style `request(method, params)` calls to the appropriate
|
|
10
|
+
* REST endpoints with snake_case ↔ camelCase translation on the wire.
|
|
11
|
+
*
|
|
12
|
+
* Hosted-native methods (added in Volume 5 of the spec) are routed natively.
|
|
13
|
+
* Legacy bridge-only methods (add_preference, add_fact, etc.) throw
|
|
14
|
+
* NotSupportedError because the hosted service has no equivalent.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type TokenProvider = () => string | Promise<string>;
|
|
18
|
+
interface RestTransportOptions {
|
|
19
|
+
/** Base URL — should end in /v1, e.g. https://memory.neo4jlabs.com/v1 */
|
|
20
|
+
endpoint: string;
|
|
21
|
+
/** Static `nams_*` API key. */
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
/** Token provider (overrides apiKey if both supplied) — for OAuth refresh flows. */
|
|
24
|
+
tokenProvider?: TokenProvider;
|
|
25
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/** Additional headers to include in every request. */
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
/** Per-request logger; see {@link Logger}. */
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
}
|
|
32
|
+
declare class RestTransport implements Transport {
|
|
33
|
+
private readonly endpoint;
|
|
34
|
+
private readonly apiKey?;
|
|
35
|
+
private readonly tokenProvider?;
|
|
36
|
+
private readonly timeout;
|
|
37
|
+
private readonly headers;
|
|
38
|
+
private readonly logger?;
|
|
39
|
+
constructor(options: RestTransportOptions);
|
|
40
|
+
connect(): Promise<void>;
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
request<T>(method: string, params: Record<string, unknown>): Promise<T>;
|
|
43
|
+
private emit;
|
|
44
|
+
private buildHeaders;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Error hierarchy for the neo4j-agent-memory TypeScript client.
|
|
49
|
+
*
|
|
50
|
+
* Every error from a failed HTTP exchange carries a `requestId` when the
|
|
51
|
+
* service emitted one. Quote it in support threads for fast log lookup.
|
|
52
|
+
*/
|
|
53
|
+
/** Options accepted by every MemoryError subclass. */
|
|
54
|
+
interface MemoryErrorOptions extends ErrorOptions {
|
|
55
|
+
/** Server-generated correlation id (x-request-id or equivalent). */
|
|
56
|
+
requestId?: string;
|
|
57
|
+
}
|
|
58
|
+
declare class MemoryError extends Error {
|
|
59
|
+
/** Server-generated correlation id, when available. */
|
|
60
|
+
readonly requestId?: string;
|
|
61
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
62
|
+
toString(): string;
|
|
63
|
+
}
|
|
64
|
+
declare class ConnectionError extends MemoryError {
|
|
65
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
66
|
+
}
|
|
67
|
+
declare class AuthenticationError extends MemoryError {
|
|
68
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
69
|
+
}
|
|
70
|
+
declare class NotFoundError extends MemoryError {
|
|
71
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
72
|
+
}
|
|
73
|
+
declare class ValidationError extends MemoryError {
|
|
74
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
75
|
+
}
|
|
76
|
+
declare class TransportError extends MemoryError {
|
|
77
|
+
readonly statusCode?: number;
|
|
78
|
+
readonly responseBody?: unknown;
|
|
79
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, options?: MemoryErrorOptions);
|
|
80
|
+
}
|
|
81
|
+
/** Raised when a transport cannot fulfil a method (e.g. REST has no equivalent). */
|
|
82
|
+
declare class NotSupportedError extends MemoryError {
|
|
83
|
+
constructor(message: string, options?: MemoryErrorOptions);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Package version constant. Kept in sync with package.json via a
|
|
88
|
+
* dedicated version-check script run in CI. Imported by the transports to build
|
|
89
|
+
* the default User-Agent header.
|
|
90
|
+
*/
|
|
91
|
+
declare const VERSION = "0.3.0";
|
|
92
|
+
|
|
93
|
+
export { AuthenticationError, ConnectionError, Logger, MemoryError, NotFoundError, NotSupportedError, RestTransport, type RestTransportOptions, type TokenProvider, Transport, TransportError, VERSION, ValidationError };
|