@rine-kit/agent-memory-postgres 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ChristmasFox / Arthur Xu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,150 @@
1
+ import type { Pool } from 'pg';
2
+ import { z } from 'zod';
3
+ import type { MemoryObservation } from '@rine-kit/agent-memory';
4
+ import { type MemoryAuthorization } from './scope.js';
5
+ export type MemoryConsolidationWorkflow = 'light' | 'rem';
6
+ export interface MemoryConsolidationConsent {
7
+ light: {
8
+ enabled: boolean;
9
+ version: number;
10
+ };
11
+ rem: {
12
+ enabled: boolean;
13
+ version: number;
14
+ };
15
+ }
16
+ export declare const MemoryConsolidationCandidateSchema: z.ZodObject<{
17
+ confidence: z.ZodEnum<{
18
+ high: "high";
19
+ medium: "medium";
20
+ }>;
21
+ subject: z.ZodEnum<{
22
+ unknown: "unknown";
23
+ self: "self";
24
+ third_party: "third_party";
25
+ }>;
26
+ kind: z.ZodEnum<{
27
+ stable_preference: "stable_preference";
28
+ verifiable_fact: "verifiable_fact";
29
+ episodic_checkpoint: "episodic_checkpoint";
30
+ }>;
31
+ key: z.ZodString;
32
+ content: z.ZodString;
33
+ evidence: z.ZodString;
34
+ validity: z.ZodEnum<{
35
+ unknown: "unknown";
36
+ stable: "stable";
37
+ "7_days": "7_days";
38
+ "30_days": "30_days";
39
+ "90_days": "90_days";
40
+ }>;
41
+ }, z.core.$strict>;
42
+ export interface MemoryConsolidationPlanner {
43
+ /** Only bounded, already-admitted text is supplied; no IDs or scope are exposed. */
44
+ plan(input: {
45
+ workflow: MemoryConsolidationWorkflow;
46
+ messages: readonly {
47
+ content: string;
48
+ createdAt: string;
49
+ }[];
50
+ }, signal: AbortSignal): Promise<unknown[]>;
51
+ }
52
+ export interface MemoryConsolidationWorkerOptions {
53
+ maxRemBatch?: number;
54
+ maxDeepCandidates?: number;
55
+ maxInputCharacters?: number;
56
+ maxCandidates?: number;
57
+ leaseMs?: number;
58
+ timeoutMs?: number;
59
+ maxAttempts?: number;
60
+ now?: () => number;
61
+ }
62
+ export type MemoryConsolidationRun = {
63
+ status: 'processed';
64
+ workflow: MemoryConsolidationWorkflow;
65
+ admitted: number;
66
+ candidates: number;
67
+ } | {
68
+ status: 'skipped';
69
+ workflow: MemoryConsolidationWorkflow;
70
+ reason: string;
71
+ admitted: number;
72
+ } | {
73
+ status: 'SKIPPED_NO_ELIGIBLE_CORPUS';
74
+ workflow: MemoryConsolidationWorkflow;
75
+ } | {
76
+ status: 'retry' | 'dead' | 'timed_out';
77
+ workflow: MemoryConsolidationWorkflow;
78
+ admitted: number;
79
+ };
80
+ export type MemoryDeepRun = {
81
+ status: 'processed';
82
+ inspected: number;
83
+ promoted: number;
84
+ rejected: number;
85
+ deferred: number;
86
+ } | {
87
+ status: 'SKIPPED_NO_ELIGIBLE_CORPUS';
88
+ };
89
+ /**
90
+ * Default-on per-scope learning controls and source admission. Consent is checked again at every step
91
+ * a worker takes; revoking it skips queued work and deletes candidates that have not been confirmed.
92
+ */
93
+ export declare class MemoryConsolidationConsentService {
94
+ private readonly pool;
95
+ private readonly namespace;
96
+ private readonly kind;
97
+ constructor(pool: Pool, namespace: string, scopeKind?: string);
98
+ /** The authorised scope of this service, or null when the request is for something else. */
99
+ private identity;
100
+ setConsent(authorization: MemoryAuthorization, workflow: MemoryConsolidationWorkflow, enabled: boolean): Promise<{
101
+ enabled: boolean;
102
+ version: number;
103
+ }>;
104
+ getConsent(authorization: MemoryAuthorization): Promise<MemoryConsolidationConsent>;
105
+ /**
106
+ * Admit one utterance of the authorised scope for learning. The host must pass the member's own
107
+ * words from the current trusted request: the observation has to carry this request as its evidence.
108
+ * Returns how many workflows queued it (0 when learning is off for this scope).
109
+ */
110
+ observe(authorization: MemoryAuthorization, observation: MemoryObservation): Promise<number>;
111
+ pendingCandidates(authorization: MemoryAuthorization): Promise<Array<{
112
+ candidateId: string;
113
+ key: string;
114
+ content: string;
115
+ kind: string;
116
+ validUntil: string | null;
117
+ status: 'pending_confirmation' | 'conflict';
118
+ }>>;
119
+ confirmCandidate(authorization: MemoryAuthorization, candidateId: string): Promise<'promoted' | 'already_promoted' | 'conflict' | 'unavailable'>;
120
+ rejectCandidate(authorization: MemoryAuthorization, candidateId: string): Promise<boolean>;
121
+ }
122
+ /** Background-capable worker; callers provide scheduling and the inference planner. */
123
+ export declare class MemoryConsolidationWorker {
124
+ private readonly pool;
125
+ private readonly namespace;
126
+ private readonly planner;
127
+ private readonly kind;
128
+ private readonly maxRemBatch;
129
+ private readonly maxDeepCandidates;
130
+ private readonly maxInputCharacters;
131
+ private readonly maxCandidates;
132
+ private readonly leaseMs;
133
+ private readonly timeoutMs;
134
+ private readonly maxAttempts;
135
+ private readonly now;
136
+ constructor(pool: Pool, namespace: string, planner: MemoryConsolidationPlanner, options?: MemoryConsolidationWorkerOptions & {
137
+ scopeKind?: string;
138
+ });
139
+ private claim;
140
+ private authorizeMetadata;
141
+ private skip;
142
+ private readMessages;
143
+ private validateCandidates;
144
+ private complete;
145
+ /** Consolidate eligible episodic candidates into long-term memory using evidence, not planner confidence. */
146
+ processDeep(limit?: number): Promise<MemoryDeepRun>;
147
+ private processDeepGroup;
148
+ private failed;
149
+ processNext(workflow: MemoryConsolidationWorkflow, signal?: AbortSignal): Promise<MemoryConsolidationRun>;
150
+ }