cogmemory 0.0.1-beta.2
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/README.md +139 -0
- package/dist/arbiter.cjs +22 -0
- package/dist/arbiter.cjs.map +1 -0
- package/dist/arbiter.d.ts +72 -0
- package/dist/arbiter.js +85 -0
- package/dist/arbiter.js.map +1 -0
- package/dist/cognitive-memory.cjs +15 -0
- package/dist/cognitive-memory.cjs.map +1 -0
- package/dist/cognitive-memory.js +1068 -0
- package/dist/cognitive-memory.js.map +1 -0
- package/dist/index.d.ts +1086 -0
- package/package.json +83 -0
- package/src/arbiter.ts +14 -0
- package/src/client.ts +105 -0
- package/src/cogmem.ts +74 -0
- package/src/cognitive/arbiter.ts +105 -0
- package/src/cognitive/fast-gate.ts +63 -0
- package/src/cognitive/index.ts +64 -0
- package/src/cognitive/memory.ts +878 -0
- package/src/cognitive/relevance.ts +199 -0
- package/src/cognitive/rules.ts +127 -0
- package/src/cognitive/types.ts +232 -0
- package/src/errors.ts +85 -0
- package/src/helpers/turn.ts +172 -0
- package/src/index.ts +134 -0
- package/src/resources/context.ts +17 -0
- package/src/resources/memories.ts +60 -0
- package/src/resources/recall.ts +17 -0
- package/src/resources/self-model.ts +21 -0
- package/src/resources/stats.ts +27 -0
- package/src/resources/tensions.ts +36 -0
- package/src/resources/turns.ts +16 -0
- package/src/types.ts +246 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract, in one file, before any implementation.
|
|
3
|
+
*
|
|
4
|
+
* Two rules run through all of it:
|
|
5
|
+
*
|
|
6
|
+
* - **Literal unions, not `string`.** `tier: MemoryTier` means an editor offers
|
|
7
|
+
* exactly four values and a typo is a compile error. `tier: string` means a
|
|
8
|
+
* runtime surprise instead.
|
|
9
|
+
* - **Request and response types are separate.** A request has optional fields
|
|
10
|
+
* with defaults; a response has ids, timestamps and computed values. Deriving
|
|
11
|
+
* one from the other produces optional ids and a type that lies about both.
|
|
12
|
+
*
|
|
13
|
+
* Where a request value is constrained by a response value, it is written as a
|
|
14
|
+
* reference (`RememberRequest["items"][number]["tier"]`) so the two cannot drift
|
|
15
|
+
* apart when a new tier is added.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type MemoryTier = "L0" | "L1" | "L2" | "L3"
|
|
19
|
+
|
|
20
|
+
export type Impact = "low" | "medium" | "critical"
|
|
21
|
+
|
|
22
|
+
export type TensionStatus = "active" | "latent" | "resolved"
|
|
23
|
+
|
|
24
|
+
/** Why a memory body was included. Each reason costs differently. */
|
|
25
|
+
export type InclusionReason = "index" | "trigger" | "tension" | "guardrail"
|
|
26
|
+
|
|
27
|
+
/** Where a statement came from. `rules` means no model was involved. */
|
|
28
|
+
export type MemorySource = "rules" | "model" | "api"
|
|
29
|
+
|
|
30
|
+
export type Scope = "memories:read" | "memories:write" | "stats:read" | "keys:manage"
|
|
31
|
+
|
|
32
|
+
export interface Memory {
|
|
33
|
+
id: string
|
|
34
|
+
content: string
|
|
35
|
+
gist?: string
|
|
36
|
+
tier: MemoryTier
|
|
37
|
+
domains: string[]
|
|
38
|
+
accessCount: number
|
|
39
|
+
source?: MemorySource
|
|
40
|
+
sessionId?: string
|
|
41
|
+
/** Epoch milliseconds. */
|
|
42
|
+
createdAt: number
|
|
43
|
+
lastAccessedAt: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RecallHit {
|
|
47
|
+
memory: Memory
|
|
48
|
+
score: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ContextEntry {
|
|
52
|
+
id: string
|
|
53
|
+
tier: MemoryTier
|
|
54
|
+
reason: InclusionReason
|
|
55
|
+
gist: string
|
|
56
|
+
/** Absent for `index` entries: a line is all those cost. */
|
|
57
|
+
body?: string
|
|
58
|
+
tokens: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ContextReport {
|
|
62
|
+
/** Prepend this to the system prompt. Empty when there is nothing to say. */
|
|
63
|
+
text: string
|
|
64
|
+
entries: ContextEntry[]
|
|
65
|
+
totalTokens: number
|
|
66
|
+
/** True when the token budget forced something out. */
|
|
67
|
+
truncated: boolean
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface RejectedStatement {
|
|
71
|
+
content: string
|
|
72
|
+
reason: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface LearnResult {
|
|
76
|
+
/** Newly created. */
|
|
77
|
+
stored: Memory[]
|
|
78
|
+
/** Restatements folded into what was already held, and what survived. */
|
|
79
|
+
mergedInto: Memory[]
|
|
80
|
+
counts: {
|
|
81
|
+
stored: number
|
|
82
|
+
merged: number
|
|
83
|
+
rejected: number
|
|
84
|
+
tensions: number
|
|
85
|
+
promoted: number
|
|
86
|
+
}
|
|
87
|
+
/** Never silent: a client that sent ten and got three needs the other seven. */
|
|
88
|
+
rejected: RejectedStatement[]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface Claim {
|
|
92
|
+
source: string
|
|
93
|
+
statement: string
|
|
94
|
+
timestamp: number
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface Tension {
|
|
98
|
+
id: string
|
|
99
|
+
status: TensionStatus
|
|
100
|
+
claimA: Claim
|
|
101
|
+
claimB: Claim
|
|
102
|
+
impact: Impact
|
|
103
|
+
actionableQuestion: string
|
|
104
|
+
resolvedBy?: string
|
|
105
|
+
pattern?: string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface DomainCapability {
|
|
109
|
+
reliabilityScore: number
|
|
110
|
+
sampleCount: number
|
|
111
|
+
knownFailurePatterns: string[]
|
|
112
|
+
recommendedStrategies: string[]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface SelfModel {
|
|
116
|
+
calibrationFactor: number
|
|
117
|
+
activeDomains: string[]
|
|
118
|
+
domains: Record<string, DomainCapability>
|
|
119
|
+
/** Below the 75% line, a guardrail is injected into every context build. */
|
|
120
|
+
weakDomains: string[]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface Health {
|
|
124
|
+
ok: boolean
|
|
125
|
+
service: string
|
|
126
|
+
version: string
|
|
127
|
+
/** `rules-only` means no model key is configured; learning is still on. */
|
|
128
|
+
extractor: "rules-only" | "rules+model"
|
|
129
|
+
limits: {
|
|
130
|
+
maxTotalTokens: number
|
|
131
|
+
maxIndexItems: number
|
|
132
|
+
defaultRecallLimit: number
|
|
133
|
+
}
|
|
134
|
+
/** Non-empty only when a setting was present but unusable. */
|
|
135
|
+
problems: string[]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface Stats {
|
|
139
|
+
memories: {
|
|
140
|
+
total: number
|
|
141
|
+
byTier: Record<MemoryTier, number>
|
|
142
|
+
sessions: number
|
|
143
|
+
firstStoredAt: number
|
|
144
|
+
lastAccessedAt: number
|
|
145
|
+
}
|
|
146
|
+
tensions: { active: number }
|
|
147
|
+
weakDomains: Array<{ domain: string; reliabilityScore: number; sampleCount: number }>
|
|
148
|
+
recent: Memory[]
|
|
149
|
+
activeTensions: Tension[]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* -------------------------------------------------------------------------- */
|
|
153
|
+
/* Requests */
|
|
154
|
+
/* -------------------------------------------------------------------------- */
|
|
155
|
+
|
|
156
|
+
export interface RememberRequest {
|
|
157
|
+
items: Array<{
|
|
158
|
+
content: string
|
|
159
|
+
domains?: string[]
|
|
160
|
+
tier?: MemoryTier
|
|
161
|
+
}>
|
|
162
|
+
/** Groups memories from one conversation. */
|
|
163
|
+
sessionId?: string
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ListMemoriesParams {
|
|
167
|
+
limit?: number
|
|
168
|
+
tier?: MemoryTier
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface RecallRequest {
|
|
172
|
+
query: string
|
|
173
|
+
limit?: number
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface RecallResponse {
|
|
177
|
+
results: RecallHit[]
|
|
178
|
+
/** True when nothing matched, so the model can admit ignorance. */
|
|
179
|
+
empty: boolean
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface TurnRequest {
|
|
183
|
+
userMessage: string
|
|
184
|
+
assistantResponse: string
|
|
185
|
+
sessionId?: string
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface ContextRequest {
|
|
189
|
+
/** The message about to be answered. Drives the triggers. */
|
|
190
|
+
userMessage?: string
|
|
191
|
+
/** Ids whose body to include regardless of tier. */
|
|
192
|
+
forceFull?: string[]
|
|
193
|
+
maxTokens?: number
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface AddTensionRequest {
|
|
197
|
+
claimA: string
|
|
198
|
+
claimB: string
|
|
199
|
+
impact?: Impact
|
|
200
|
+
actionableQuestion: string
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface ResolveTensionRequest {
|
|
204
|
+
resolvedBy: string
|
|
205
|
+
/** The reusable pattern the resolution revealed. */
|
|
206
|
+
pattern?: string
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface DomainOutcomeRequest {
|
|
210
|
+
domain: string
|
|
211
|
+
success: boolean
|
|
212
|
+
failurePattern?: string
|
|
213
|
+
strategy?: string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* -------------------------------------------------------------------------- */
|
|
217
|
+
/* Client configuration */
|
|
218
|
+
/* -------------------------------------------------------------------------- */
|
|
219
|
+
|
|
220
|
+
export interface CognitiveMemoryConfig {
|
|
221
|
+
apiKey: string
|
|
222
|
+
/** Defaults to the current origin in a browser, or localhost otherwise. */
|
|
223
|
+
baseUrl?: string
|
|
224
|
+
/** Per-request timeout in ms. */
|
|
225
|
+
timeout?: number
|
|
226
|
+
/** Retries for transient failures. 0 disables. */
|
|
227
|
+
retry?: number
|
|
228
|
+
/**
|
|
229
|
+
* Log every request and response.
|
|
230
|
+
*
|
|
231
|
+
* On by default for anyone who has been burned by a wrong base URL, which is
|
|
232
|
+
* everyone exactly once.
|
|
233
|
+
*/
|
|
234
|
+
debug?: boolean
|
|
235
|
+
headers?: Record<string, string>
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The error envelope every non-2xx response carries. */
|
|
239
|
+
export interface CognitiveMemoryErrorBody {
|
|
240
|
+
error: string
|
|
241
|
+
message: string
|
|
242
|
+
requiredScope?: string
|
|
243
|
+
resource?: string
|
|
244
|
+
id?: string
|
|
245
|
+
issues?: string[]
|
|
246
|
+
}
|