@n8n/agents 0.7.1 → 0.8.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/dist/build.tsbuildinfo +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/dist/runtime/agent-runtime.d.ts +24 -12
- package/dist/runtime/agent-runtime.js +241 -91
- package/dist/runtime/agent-runtime.js.map +1 -1
- package/dist/runtime/background-task-tracker.d.ts +6 -0
- package/dist/runtime/background-task-tracker.js +26 -0
- package/dist/runtime/background-task-tracker.js.map +1 -0
- package/dist/runtime/deferred-tool-manager.d.ts +28 -0
- package/dist/runtime/deferred-tool-manager.js +205 -0
- package/dist/runtime/deferred-tool-manager.js.map +1 -0
- package/dist/runtime/memory-store.d.ts +21 -36
- package/dist/runtime/memory-store.js +118 -51
- package/dist/runtime/memory-store.js.map +1 -1
- package/dist/runtime/message-list.d.ts +1 -7
- package/dist/runtime/message-list.js +3 -6
- package/dist/runtime/message-list.js.map +1 -1
- package/dist/runtime/observation-log-defaults.d.ts +20 -0
- package/dist/runtime/observation-log-defaults.js +523 -0
- package/dist/runtime/observation-log-defaults.js.map +1 -0
- package/dist/runtime/observation-log-observer.d.ts +64 -0
- package/dist/runtime/observation-log-observer.js +235 -0
- package/dist/runtime/observation-log-observer.js.map +1 -0
- package/dist/runtime/observation-log-reflector.d.ts +36 -0
- package/dist/runtime/observation-log-reflector.js +292 -0
- package/dist/runtime/observation-log-reflector.js.map +1 -0
- package/dist/runtime/observation-log-renderer.d.ts +6 -0
- package/dist/runtime/observation-log-renderer.js +73 -0
- package/dist/runtime/observation-log-renderer.js.map +1 -0
- package/dist/runtime/observation-log-store.d.ts +3 -0
- package/dist/runtime/observation-log-store.js +26 -0
- package/dist/runtime/observation-log-store.js.map +1 -0
- package/dist/runtime/scoped-memory-task-runner.d.ts +79 -0
- package/dist/runtime/scoped-memory-task-runner.js +134 -0
- package/dist/runtime/scoped-memory-task-runner.js.map +1 -0
- package/dist/sdk/agent.d.ts +13 -1
- package/dist/sdk/agent.js +58 -9
- package/dist/sdk/agent.js.map +1 -1
- package/dist/sdk/catalog.d.ts +1 -0
- package/dist/sdk/catalog.js +1 -0
- package/dist/sdk/catalog.js.map +1 -1
- package/dist/sdk/memory.d.ts +12 -12
- package/dist/sdk/memory.js +71 -51
- package/dist/sdk/memory.js.map +1 -1
- package/dist/storage/base-memory.d.ts +0 -10
- package/dist/storage/base-memory.js +0 -6
- package/dist/storage/base-memory.js.map +1 -1
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.js +7 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/runtime/event.d.ts +1 -0
- package/dist/types/sdk/agent-builder.d.ts +5 -0
- package/dist/types/sdk/agent.d.ts +6 -0
- package/dist/types/sdk/memory.d.ts +16 -24
- package/dist/types/sdk/observation-log.d.ts +99 -0
- package/dist/types/sdk/observation-log.js +17 -0
- package/dist/types/sdk/observation-log.js.map +1 -0
- package/dist/types/sdk/observation.d.ts +3 -94
- package/dist/types/sdk/observation.js +0 -2
- package/dist/types/sdk/observation.js.map +1 -1
- package/dist/types/sdk/provider.d.ts +5 -2
- package/package.json +3 -7
- package/dist/runtime/working-memory.d.ts +0 -14
- package/dist/runtime/working-memory.js +0 -69
- package/dist/runtime/working-memory.js.map +0 -1
- package/dist/storage/postgres-memory.d.ts +0 -96
- package/dist/storage/postgres-memory.js +0 -431
- package/dist/storage/postgres-memory.js.map +0 -1
- package/dist/storage/sqlite-memory.d.ts +0 -70
- package/dist/storage/sqlite-memory.js +0 -354
- package/dist/storage/sqlite-memory.js.map +0 -1
|
@@ -1,100 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { AgentDbMessage } from './message';
|
|
4
|
-
import type { BuiltTelemetry } from '../telemetry';
|
|
5
|
-
import type { JSONValue } from '../utils/json';
|
|
6
|
-
export declare const OBSERVATION_SCHEMA_VERSION = 1;
|
|
7
|
-
export type ScopeKind = 'thread' | 'resource' | 'agent';
|
|
8
|
-
export interface Observation {
|
|
9
|
-
id: string;
|
|
10
|
-
scopeKind: ScopeKind;
|
|
11
|
-
scopeId: string;
|
|
12
|
-
kind: string;
|
|
13
|
-
payload: JSONValue;
|
|
14
|
-
durationMs: number | null;
|
|
15
|
-
schemaVersion: number;
|
|
16
|
-
createdAt: Date;
|
|
17
|
-
}
|
|
18
|
-
export type NewObservation = Omit<Observation, 'id'>;
|
|
1
|
+
import type { ObservationLogScopeKind } from './observation-log';
|
|
2
|
+
export type ScopeKind = ObservationLogScopeKind;
|
|
19
3
|
export interface ObservationCursor {
|
|
20
|
-
scopeKind:
|
|
4
|
+
scopeKind: ObservationLogScopeKind;
|
|
21
5
|
scopeId: string;
|
|
22
6
|
lastObservedMessageId: string;
|
|
23
7
|
lastObservedAt: Date;
|
|
24
8
|
updatedAt: Date;
|
|
25
9
|
}
|
|
26
|
-
export interface ObservationLockHandle {
|
|
27
|
-
scopeKind: ScopeKind;
|
|
28
|
-
scopeId: string;
|
|
29
|
-
holderId: string;
|
|
30
|
-
heldUntil: Date;
|
|
31
|
-
}
|
|
32
|
-
export type ObserveFn = (ctx: {
|
|
33
|
-
deltaMessages: AgentDbMessage[];
|
|
34
|
-
currentWorkingMemory: string | null;
|
|
35
|
-
cursor: ObservationCursor | null;
|
|
36
|
-
threadId: string;
|
|
37
|
-
resourceId: string;
|
|
38
|
-
now: Date;
|
|
39
|
-
trigger: ObservationalMemoryTrigger;
|
|
40
|
-
telemetry: BuiltTelemetry | undefined;
|
|
41
|
-
}) => Promise<NewObservation[]>;
|
|
42
|
-
export type CompactFn = (ctx: {
|
|
43
|
-
observations: Observation[];
|
|
44
|
-
currentWorkingMemory: string | null;
|
|
45
|
-
workingMemoryTemplate: string;
|
|
46
|
-
structured: boolean;
|
|
47
|
-
schema?: z.ZodObject<z.ZodRawShape>;
|
|
48
|
-
threadId: string;
|
|
49
|
-
resourceId: string;
|
|
50
|
-
model: ModelConfig;
|
|
51
|
-
compactorPrompt: string;
|
|
52
|
-
telemetry: BuiltTelemetry | undefined;
|
|
53
|
-
}) => Promise<{
|
|
54
|
-
content: string;
|
|
55
|
-
}>;
|
|
56
|
-
export interface BuiltObservationStore {
|
|
57
|
-
appendObservations(rows: NewObservation[]): Promise<Observation[]>;
|
|
58
|
-
getObservations(opts: {
|
|
59
|
-
scopeKind: ScopeKind;
|
|
60
|
-
scopeId: string;
|
|
61
|
-
since?: {
|
|
62
|
-
sinceCreatedAt: Date;
|
|
63
|
-
sinceObservationId: string;
|
|
64
|
-
};
|
|
65
|
-
kindIs?: string;
|
|
66
|
-
limit?: number;
|
|
67
|
-
schemaVersionAtMost?: number;
|
|
68
|
-
}): Promise<Observation[]>;
|
|
69
|
-
getMessagesForScope(scopeKind: ScopeKind, scopeId: string, opts?: {
|
|
70
|
-
since?: {
|
|
71
|
-
sinceCreatedAt: Date;
|
|
72
|
-
sinceMessageId: string;
|
|
73
|
-
};
|
|
74
|
-
}): Promise<AgentDbMessage[]>;
|
|
75
|
-
deleteObservations(ids: string[]): Promise<void>;
|
|
76
|
-
getCursor(scopeKind: ScopeKind, scopeId: string): Promise<ObservationCursor | null>;
|
|
77
|
-
setCursor(cursor: ObservationCursor): Promise<void>;
|
|
78
|
-
acquireObservationLock(scopeKind: ScopeKind, scopeId: string, opts: {
|
|
79
|
-
ttlMs: number;
|
|
80
|
-
holderId: string;
|
|
81
|
-
}): Promise<ObservationLockHandle | null>;
|
|
82
|
-
releaseObservationLock(handle: ObservationLockHandle): Promise<void>;
|
|
83
|
-
}
|
|
84
|
-
export type ObservationalMemoryTrigger = {
|
|
85
|
-
type: 'per-turn';
|
|
86
|
-
} | {
|
|
87
|
-
type: 'idle-timer';
|
|
88
|
-
idleMs: number;
|
|
89
|
-
gapThresholdMs?: number;
|
|
90
|
-
};
|
|
91
|
-
export interface ObservationalMemoryConfig {
|
|
92
|
-
observe?: ObserveFn;
|
|
93
|
-
compact?: CompactFn;
|
|
94
|
-
trigger?: ObservationalMemoryTrigger;
|
|
95
|
-
compactionThreshold?: number;
|
|
96
|
-
observerPrompt?: string;
|
|
97
|
-
compactorPrompt?: string;
|
|
98
|
-
lockTtlMs?: number;
|
|
99
|
-
sync?: boolean;
|
|
100
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.js","sourceRoot":"","sources":["../../../src/types/sdk/observation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observation.js","sourceRoot":"","sources":["../../../src/types/sdk/observation.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type Provider = 'anthropic' | 'cerebras' | 'deepinfra' | 'deepseek' | 'google' | 'groq' | 'mistral' | 'openai' | 'openrouter' | 'perplexity' | 'togetherai' | 'vercel' | 'xai' | (string & {});
|
|
2
|
-
export
|
|
2
|
+
export type AnthropicThinkingConfig = {
|
|
3
|
+
mode: 'adaptive';
|
|
4
|
+
} | {
|
|
5
|
+
mode?: 'enabled';
|
|
3
6
|
budgetTokens?: number;
|
|
4
|
-
}
|
|
7
|
+
};
|
|
5
8
|
export interface OpenAIThinkingConfig {
|
|
6
9
|
reasoningEffort?: 'low' | 'medium' | 'high';
|
|
7
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "AI agent SDK for n8n's code-first execution engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,20 +23,18 @@
|
|
|
23
23
|
"@ai-sdk/openai": "^3.0.41",
|
|
24
24
|
"@ai-sdk/provider-utils": "^4.0.21",
|
|
25
25
|
"@ai-sdk/xai": "^3.0.67",
|
|
26
|
-
"@libsql/client": "^0.17.0",
|
|
27
26
|
"@modelcontextprotocol/sdk": "1.26.0",
|
|
28
27
|
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
29
28
|
"ai": "^6.0.116",
|
|
30
29
|
"ajv": "^8.18.0",
|
|
31
|
-
"pg": "8.17.0",
|
|
32
30
|
"zod": "3.25.67",
|
|
33
|
-
"@n8n/ai-utilities": "0.
|
|
31
|
+
"@n8n/ai-utilities": "0.16.1"
|
|
34
32
|
},
|
|
35
33
|
"peerDependencies": {
|
|
36
34
|
"@opentelemetry/exporter-trace-otlp-http": ">=0.50.0",
|
|
37
35
|
"@opentelemetry/sdk-trace-base": ">=1.0.0",
|
|
38
36
|
"@opentelemetry/sdk-trace-node": ">=1.0.0",
|
|
39
|
-
"langsmith": "
|
|
37
|
+
"langsmith": "0.6.0"
|
|
40
38
|
},
|
|
41
39
|
"peerDependenciesMeta": {
|
|
42
40
|
"langsmith": {
|
|
@@ -54,8 +52,6 @@
|
|
|
54
52
|
},
|
|
55
53
|
"devDependencies": {
|
|
56
54
|
"@types/json-schema": "^7.0.15",
|
|
57
|
-
"@types/pg": "^8.15.6",
|
|
58
|
-
"testcontainers": "^11.13.0",
|
|
59
55
|
"@n8n/typescript-config": "1.4.0"
|
|
60
56
|
},
|
|
61
57
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { BuiltTool } from '../types';
|
|
3
|
-
type ZodObjectSchema = z.ZodObject<z.ZodRawShape>;
|
|
4
|
-
export declare const UPDATE_WORKING_MEMORY_TOOL_NAME = "update_working_memory";
|
|
5
|
-
export declare const WORKING_MEMORY_DEFAULT_INSTRUCTION: string;
|
|
6
|
-
export declare function buildWorkingMemoryInstruction(template: string, structured: boolean, instruction?: string): string;
|
|
7
|
-
export declare function templateFromSchema(schema: ZodObjectSchema): string;
|
|
8
|
-
export interface WorkingMemoryToolConfig {
|
|
9
|
-
structured: boolean;
|
|
10
|
-
schema?: ZodObjectSchema;
|
|
11
|
-
persist: (content: string) => Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export declare function buildWorkingMemoryTool(config: WorkingMemoryToolConfig): BuiltTool;
|
|
14
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WORKING_MEMORY_DEFAULT_INSTRUCTION = exports.UPDATE_WORKING_MEMORY_TOOL_NAME = void 0;
|
|
4
|
-
exports.buildWorkingMemoryInstruction = buildWorkingMemoryInstruction;
|
|
5
|
-
exports.templateFromSchema = templateFromSchema;
|
|
6
|
-
exports.buildWorkingMemoryTool = buildWorkingMemoryTool;
|
|
7
|
-
const zod_1 = require("zod");
|
|
8
|
-
exports.UPDATE_WORKING_MEMORY_TOOL_NAME = 'update_working_memory';
|
|
9
|
-
exports.WORKING_MEMORY_DEFAULT_INSTRUCTION = [
|
|
10
|
-
'You have persistent working memory that survives across conversations.',
|
|
11
|
-
'Your current working memory state is shown below.',
|
|
12
|
-
`When you learn new information about the user or conversation that should be remembered, call the \`${exports.UPDATE_WORKING_MEMORY_TOOL_NAME}\` tool.`,
|
|
13
|
-
'Only call it when something has actually changed — do NOT call it if nothing new was learned.',
|
|
14
|
-
].join('\n');
|
|
15
|
-
function buildWorkingMemoryInstruction(template, structured, instruction) {
|
|
16
|
-
const format = structured
|
|
17
|
-
? 'The memory argument must be valid JSON matching the schema'
|
|
18
|
-
: 'Update the template with any new information learned';
|
|
19
|
-
const body = instruction ?? exports.WORKING_MEMORY_DEFAULT_INSTRUCTION;
|
|
20
|
-
return [
|
|
21
|
-
'',
|
|
22
|
-
'## Working Memory',
|
|
23
|
-
'',
|
|
24
|
-
body,
|
|
25
|
-
`${format}.`,
|
|
26
|
-
'',
|
|
27
|
-
'Current template:',
|
|
28
|
-
'```',
|
|
29
|
-
template,
|
|
30
|
-
'```',
|
|
31
|
-
].join('\n');
|
|
32
|
-
}
|
|
33
|
-
function templateFromSchema(schema) {
|
|
34
|
-
const obj = {};
|
|
35
|
-
for (const [key, field] of Object.entries(schema.shape)) {
|
|
36
|
-
const desc = field.description;
|
|
37
|
-
obj[key] = desc ?? '';
|
|
38
|
-
}
|
|
39
|
-
return JSON.stringify(obj, null, 2);
|
|
40
|
-
}
|
|
41
|
-
function buildWorkingMemoryTool(config) {
|
|
42
|
-
if (config.structured && config.schema) {
|
|
43
|
-
const schema = config.schema;
|
|
44
|
-
return {
|
|
45
|
-
name: exports.UPDATE_WORKING_MEMORY_TOOL_NAME,
|
|
46
|
-
description: 'Update your persistent working memory with new information about the user or conversation. Only call this when something has actually changed.',
|
|
47
|
-
inputSchema: schema,
|
|
48
|
-
handler: async (input) => {
|
|
49
|
-
const content = JSON.stringify(input, null, 2);
|
|
50
|
-
await config.persist(content);
|
|
51
|
-
return { success: true, message: 'Working memory updated.' };
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const freeformSchema = zod_1.z.object({
|
|
56
|
-
memory: zod_1.z.string().describe('The updated working memory content.'),
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
name: exports.UPDATE_WORKING_MEMORY_TOOL_NAME,
|
|
60
|
-
description: 'Update your persistent working memory with new information about the user or conversation. Only call this when something has actually changed.',
|
|
61
|
-
inputSchema: freeformSchema,
|
|
62
|
-
handler: async (input) => {
|
|
63
|
-
const { memory } = input;
|
|
64
|
-
await config.persist(memory);
|
|
65
|
-
return { success: true, message: 'Working memory updated.' };
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=working-memory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"working-memory.js","sourceRoot":"","sources":["../../src/runtime/working-memory.ts"],"names":[],"mappings":";;;AA4BA,sEAuBC;AAKD,gDAOC;AAkBD,wDA+BC;AAhHD,6BAAwB;AAMX,QAAA,+BAA+B,GAAG,uBAAuB,CAAC;AAM1D,QAAA,kCAAkC,GAAG;IACjD,wEAAwE;IACxE,mDAAmD;IACnD,uGAAuG,uCAA+B,UAAU;IAChJ,+FAA+F;CAC/F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAWb,SAAgB,6BAA6B,CAC5C,QAAgB,EAChB,UAAmB,EACnB,WAAoB;IAEpB,MAAM,MAAM,GAAG,UAAU;QACxB,CAAC,CAAC,4DAA4D;QAC9D,CAAC,CAAC,sDAAsD,CAAC;IAE1D,MAAM,IAAI,GAAG,WAAW,IAAI,0CAAkC,CAAC;IAE/D,OAAO;QACN,EAAE;QACF,mBAAmB;QACnB,EAAE;QACF,IAAI;QACJ,GAAG,MAAM,GAAG;QACZ,EAAE;QACF,mBAAmB;QACnB,KAAK;QACL,QAAQ;QACR,KAAK;KACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAKD,SAAgB,kBAAkB,CAAC,MAAuB;IACzD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC;QAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACrC,CAAC;AAkBD,SAAgB,sBAAsB,CAAC,MAA+B;IACrE,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,OAAO;YACN,IAAI,EAAE,uCAA+B;YACrC,WAAW,EACV,gJAAgJ;YACjJ,WAAW,EAAE,MAAM;YACnB,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE;gBACjC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC/C,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC;YAC9D,CAAC;SACD,CAAC;IACH,CAAC;IAED,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;QAC/B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;KAClE,CAAC,CAAC;IAEH,OAAO;QACN,IAAI,EAAE,uCAA+B;QACrC,WAAW,EACV,gJAAgJ;QACjJ,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE;YACjC,MAAM,EAAE,MAAM,EAAE,GAAG,KAAuC,CAAC;YAC3D,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC;QAC9D,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { BaseMemory } from './base-memory';
|
|
2
|
-
import type { Thread } from '../types/sdk/memory';
|
|
3
|
-
import type { AgentDbMessage } from '../types/sdk/message';
|
|
4
|
-
export type PostgresConnectionOptions = {
|
|
5
|
-
connectionType: 'url';
|
|
6
|
-
connection: {
|
|
7
|
-
url: string;
|
|
8
|
-
};
|
|
9
|
-
} | {
|
|
10
|
-
connectionType: 'config';
|
|
11
|
-
connection: {
|
|
12
|
-
host?: string;
|
|
13
|
-
port?: number;
|
|
14
|
-
database?: string;
|
|
15
|
-
user?: string;
|
|
16
|
-
password?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export type PostgresMemoryOptions = {
|
|
20
|
-
pool?: {
|
|
21
|
-
max?: number;
|
|
22
|
-
min?: number;
|
|
23
|
-
idleTimeoutMillis?: number;
|
|
24
|
-
connectionTimeoutMillis?: number;
|
|
25
|
-
allowExitOnIdle?: boolean;
|
|
26
|
-
};
|
|
27
|
-
ssl?: boolean;
|
|
28
|
-
namespace?: string;
|
|
29
|
-
};
|
|
30
|
-
export type PostgresConstructorOptions = ({
|
|
31
|
-
type: 'credential';
|
|
32
|
-
credential: string;
|
|
33
|
-
} | {
|
|
34
|
-
type: 'connection';
|
|
35
|
-
connection: PostgresConnectionOptions;
|
|
36
|
-
}) & {
|
|
37
|
-
options?: PostgresMemoryOptions;
|
|
38
|
-
};
|
|
39
|
-
export declare class PostgresMemory extends BaseMemory<PostgresConstructorOptions> {
|
|
40
|
-
protected readonly constructorOptions: PostgresConstructorOptions;
|
|
41
|
-
private readonly resolveConfig?;
|
|
42
|
-
private initPromise;
|
|
43
|
-
private embeddingsInitPromise;
|
|
44
|
-
private readonly ns;
|
|
45
|
-
constructor(constructorOptions: PostgresConstructorOptions, resolveConfig?: ((credential: string) => Promise<PostgresConnectionOptions>) | undefined);
|
|
46
|
-
private ensureInitialized;
|
|
47
|
-
private _initialize;
|
|
48
|
-
getThread(threadId: string): Promise<Thread | null>;
|
|
49
|
-
saveThread(thread: Omit<Thread, 'createdAt' | 'updatedAt'>): Promise<Thread>;
|
|
50
|
-
deleteThread(threadId: string): Promise<void>;
|
|
51
|
-
getMessages(threadId: string, opts?: {
|
|
52
|
-
limit?: number;
|
|
53
|
-
before?: Date;
|
|
54
|
-
}): Promise<AgentDbMessage[]>;
|
|
55
|
-
saveMessages(args: {
|
|
56
|
-
threadId: string;
|
|
57
|
-
resourceId?: string;
|
|
58
|
-
messages: AgentDbMessage[];
|
|
59
|
-
}): Promise<void>;
|
|
60
|
-
deleteMessages(messageIds: string[]): Promise<void>;
|
|
61
|
-
getWorkingMemory(params: {
|
|
62
|
-
threadId: string;
|
|
63
|
-
resourceId: string;
|
|
64
|
-
scope: 'resource' | 'thread';
|
|
65
|
-
}): Promise<string | null>;
|
|
66
|
-
saveWorkingMemory(params: {
|
|
67
|
-
threadId: string;
|
|
68
|
-
resourceId: string;
|
|
69
|
-
scope: 'resource' | 'thread';
|
|
70
|
-
}, content: string): Promise<void>;
|
|
71
|
-
private embeddingDimension;
|
|
72
|
-
private ensureEmbeddingsTable;
|
|
73
|
-
private _initializeEmbeddingsTable;
|
|
74
|
-
saveEmbeddings(opts: {
|
|
75
|
-
scope?: 'thread' | 'resource';
|
|
76
|
-
threadId?: string;
|
|
77
|
-
resourceId?: string;
|
|
78
|
-
entries: Array<{
|
|
79
|
-
id: string;
|
|
80
|
-
vector: number[];
|
|
81
|
-
text: string;
|
|
82
|
-
model: string;
|
|
83
|
-
}>;
|
|
84
|
-
}): Promise<void>;
|
|
85
|
-
queryEmbeddings(opts: {
|
|
86
|
-
scope?: 'thread' | 'resource';
|
|
87
|
-
threadId?: string;
|
|
88
|
-
resourceId?: string;
|
|
89
|
-
vector: number[];
|
|
90
|
-
topK: number;
|
|
91
|
-
}): Promise<Array<{
|
|
92
|
-
id: string;
|
|
93
|
-
score: number;
|
|
94
|
-
}>>;
|
|
95
|
-
close(): Promise<void>;
|
|
96
|
-
}
|