@manta-eu/client 0.1.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/LICENSE +21 -0
- package/dist/generated/graphql.d.ts +4719 -0
- package/dist/generated/graphql.d.ts.map +1 -0
- package/dist/generated/graphql.js +2452 -0
- package/dist/graphql-clients.d.ts +9 -0
- package/dist/graphql-clients.d.ts.map +1 -0
- package/dist/graphql-clients.js +27 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/shared/action-plan.d.ts +2 -0
- package/dist/shared/action-plan.d.ts.map +1 -0
- package/dist/shared/action-plan.js +1 -0
- package/dist/shared/agent-mode.d.ts +9 -0
- package/dist/shared/agent-mode.d.ts.map +1 -0
- package/dist/shared/agent-mode.js +38 -0
- package/dist/shared/agent-types.d.ts +41 -0
- package/dist/shared/agent-types.d.ts.map +1 -0
- package/dist/shared/agent-types.js +12 -0
- package/dist/shared/chat-context.d.ts +7 -0
- package/dist/shared/chat-context.d.ts.map +1 -0
- package/dist/shared/chat-context.js +38 -0
- package/dist/shared/chat-manager.d.ts +183 -0
- package/dist/shared/chat-manager.d.ts.map +1 -0
- package/dist/shared/chat-manager.js +75 -0
- package/dist/shared/chat-turn-errors.d.ts +16 -0
- package/dist/shared/chat-turn-errors.d.ts.map +1 -0
- package/dist/shared/chat-turn-errors.js +18 -0
- package/dist/shared/constants.d.ts +11 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/constants.js +10 -0
- package/dist/shared/conversation-starter-defaults.d.ts +8 -0
- package/dist/shared/conversation-starter-defaults.d.ts.map +1 -0
- package/dist/shared/conversation-starter-defaults.js +20 -0
- package/dist/shared/datastore-id.d.ts +4 -0
- package/dist/shared/datastore-id.d.ts.map +1 -0
- package/dist/shared/datastore-id.js +17 -0
- package/dist/shared/datastore-path.d.ts +19 -0
- package/dist/shared/datastore-path.d.ts.map +1 -0
- package/dist/shared/datastore-path.js +62 -0
- package/dist/shared/datastore-route-table.d.ts +36 -0
- package/dist/shared/datastore-route-table.d.ts.map +1 -0
- package/dist/shared/datastore-route-table.js +43 -0
- package/dist/shared/duration.d.ts +6 -0
- package/dist/shared/duration.d.ts.map +1 -0
- package/dist/shared/duration.js +55 -0
- package/dist/shared/entity-set.d.ts +14 -0
- package/dist/shared/entity-set.d.ts.map +1 -0
- package/dist/shared/entity-set.js +25 -0
- package/dist/shared/error-utils.d.ts +23 -0
- package/dist/shared/error-utils.d.ts.map +1 -0
- package/dist/shared/error-utils.js +56 -0
- package/dist/shared/explorer-paths.d.ts +4 -0
- package/dist/shared/explorer-paths.d.ts.map +1 -0
- package/dist/shared/explorer-paths.js +7 -0
- package/dist/shared/fileIri.d.ts +12 -0
- package/dist/shared/fileIri.d.ts.map +1 -0
- package/dist/shared/fileIri.js +18 -0
- package/dist/shared/index.d.ts +22 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +8 -0
- package/dist/shared/live-context.d.ts +2 -0
- package/dist/shared/live-context.d.ts.map +1 -0
- package/dist/shared/live-context.js +15 -0
- package/dist/shared/maintenance-schedule.d.ts +11 -0
- package/dist/shared/maintenance-schedule.d.ts.map +1 -0
- package/dist/shared/maintenance-schedule.js +38 -0
- package/dist/shared/memory-citation-sampling.d.ts +16 -0
- package/dist/shared/memory-citation-sampling.d.ts.map +1 -0
- package/dist/shared/memory-citation-sampling.js +14 -0
- package/dist/shared/memory-confidence.d.ts +3 -0
- package/dist/shared/memory-confidence.d.ts.map +1 -0
- package/dist/shared/memory-confidence.js +7 -0
- package/dist/shared/memory-consolidation-limits.d.ts +6 -0
- package/dist/shared/memory-consolidation-limits.d.ts.map +1 -0
- package/dist/shared/memory-consolidation-limits.js +5 -0
- package/dist/shared/memory-dates.d.ts +3 -0
- package/dist/shared/memory-dates.d.ts.map +1 -0
- package/dist/shared/memory-dates.js +7 -0
- package/dist/shared/memory-decay.d.ts +22 -0
- package/dist/shared/memory-decay.d.ts.map +1 -0
- package/dist/shared/memory-decay.js +43 -0
- package/dist/shared/memory-diversity.d.ts +10 -0
- package/dist/shared/memory-diversity.d.ts.map +1 -0
- package/dist/shared/memory-diversity.js +44 -0
- package/dist/shared/memory-entity-recall.d.ts +8 -0
- package/dist/shared/memory-entity-recall.d.ts.map +1 -0
- package/dist/shared/memory-entity-recall.js +17 -0
- package/dist/shared/memory-importance.d.ts +4 -0
- package/dist/shared/memory-importance.d.ts.map +1 -0
- package/dist/shared/memory-importance.js +9 -0
- package/dist/shared/memory-keyword-recall.d.ts +13 -0
- package/dist/shared/memory-keyword-recall.d.ts.map +1 -0
- package/dist/shared/memory-keyword-recall.js +141 -0
- package/dist/shared/memory-kind-iris.d.ts +9 -0
- package/dist/shared/memory-kind-iris.d.ts.map +1 -0
- package/dist/shared/memory-kind-iris.js +22 -0
- package/dist/shared/memory-preload-gate.d.ts +37 -0
- package/dist/shared/memory-preload-gate.d.ts.map +1 -0
- package/dist/shared/memory-preload-gate.js +95 -0
- package/dist/shared/memory-sources.d.ts +3 -0
- package/dist/shared/memory-sources.d.ts.map +1 -0
- package/dist/shared/memory-sources.js +3 -0
- package/dist/shared/memory-teams.d.ts +2 -0
- package/dist/shared/memory-teams.d.ts.map +1 -0
- package/dist/shared/memory-teams.js +3 -0
- package/dist/shared/memory-token-budget.d.ts +8 -0
- package/dist/shared/memory-token-budget.d.ts.map +1 -0
- package/dist/shared/memory-token-budget.js +23 -0
- package/dist/shared/memory-volatility.d.ts +24 -0
- package/dist/shared/memory-volatility.d.ts.map +1 -0
- package/dist/shared/memory-volatility.js +55 -0
- package/dist/shared/message-utils.d.ts +12 -0
- package/dist/shared/message-utils.d.ts.map +1 -0
- package/dist/shared/message-utils.js +22 -0
- package/dist/shared/model.d.ts +165 -0
- package/dist/shared/model.d.ts.map +1 -0
- package/dist/shared/model.js +93 -0
- package/dist/shared/org-roles.d.ts +11 -0
- package/dist/shared/org-roles.d.ts.map +1 -0
- package/dist/shared/org-roles.js +10 -0
- package/dist/shared/page-context.d.ts +7 -0
- package/dist/shared/page-context.d.ts.map +1 -0
- package/dist/shared/page-context.js +1 -0
- package/dist/shared/permissions.d.ts +9 -0
- package/dist/shared/permissions.d.ts.map +1 -0
- package/dist/shared/permissions.js +10 -0
- package/dist/shared/questionnaire.d.ts +32 -0
- package/dist/shared/questionnaire.d.ts.map +1 -0
- package/dist/shared/questionnaire.js +68 -0
- package/dist/shared/rdf-namespaces.d.ts +11 -0
- package/dist/shared/rdf-namespaces.d.ts.map +1 -0
- package/dist/shared/rdf-namespaces.js +15 -0
- package/dist/shared/rule-iri.d.ts +4 -0
- package/dist/shared/rule-iri.d.ts.map +1 -0
- package/dist/shared/rule-iri.js +13 -0
- package/dist/shared/rule-search.d.ts +2 -0
- package/dist/shared/rule-search.d.ts.map +1 -0
- package/dist/shared/rule-search.js +1 -0
- package/dist/shared/session-types.d.ts +14 -0
- package/dist/shared/session-types.d.ts.map +1 -0
- package/dist/shared/session-types.js +1 -0
- package/dist/shared/spa-routes.d.ts +3 -0
- package/dist/shared/spa-routes.d.ts.map +1 -0
- package/dist/shared/spa-routes.js +5 -0
- package/dist/shared/stakeholder-iri.d.ts +7 -0
- package/dist/shared/stakeholder-iri.d.ts.map +1 -0
- package/dist/shared/stakeholder-iri.js +20 -0
- package/dist/shared/team-activation.d.ts +7 -0
- package/dist/shared/team-activation.d.ts.map +1 -0
- package/dist/shared/team-activation.js +3 -0
- package/dist/shared/team.d.ts +150 -0
- package/dist/shared/team.d.ts.map +1 -0
- package/dist/shared/team.js +88 -0
- package/dist/shared/tools/coercers.d.ts +6 -0
- package/dist/shared/tools/coercers.d.ts.map +1 -0
- package/dist/shared/tools/coercers.js +63 -0
- package/dist/shared/tools/index.d.ts +4 -0
- package/dist/shared/tools/index.d.ts.map +1 -0
- package/dist/shared/tools/index.js +2 -0
- package/dist/shared/tools/metadata.d.ts +12 -0
- package/dist/shared/tools/metadata.d.ts.map +1 -0
- package/dist/shared/tools/metadata.js +215 -0
- package/dist/shared/tools/test-triple.d.ts +16 -0
- package/dist/shared/tools/test-triple.d.ts.map +1 -0
- package/dist/shared/tools/test-triple.js +26 -0
- package/dist/shared/tools/types.d.ts +236 -0
- package/dist/shared/tools/types.d.ts.map +1 -0
- package/dist/shared/tools/types.js +1 -0
- package/dist/shared/upload.d.ts +26 -0
- package/dist/shared/upload.d.ts.map +1 -0
- package/dist/shared/upload.js +26 -0
- package/dist/shared/website-url.d.ts +5 -0
- package/dist/shared/website-url.d.ts.map +1 -0
- package/dist/shared/website-url.js +31 -0
- package/dist/shared/workspace-artifacts.d.ts +21 -0
- package/dist/shared/workspace-artifacts.d.ts.map +1 -0
- package/dist/shared/workspace-artifacts.js +59 -0
- package/dist/shared/writable-shape-query.d.ts +2 -0
- package/dist/shared/writable-shape-query.d.ts.map +1 -0
- package/dist/shared/writable-shape-query.js +21 -0
- package/dist/types/jsonld.d.ts +2 -0
- package/dist/types/jsonld.d.ts.map +1 -0
- package/dist/types/jsonld.js +1 -0
- package/dist/types/sparql-types.d.ts +3 -0
- package/dist/types/sparql-types.d.ts.map +1 -0
- package/dist/types/sparql-types.js +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const personalMemoryScope = "user";
|
|
2
|
+
export type MemoryDecayCandidate = {
|
|
3
|
+
scope?: string | null;
|
|
4
|
+
memoryUseCount?: number | null;
|
|
5
|
+
memoryCiteCount?: number | null;
|
|
6
|
+
memoryLastUsedAt?: Date | string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare const preloadedUseWeight = 1;
|
|
9
|
+
export declare const citedUseWeight = 0;
|
|
10
|
+
export type UseWeights = {
|
|
11
|
+
preloaded?: number;
|
|
12
|
+
cited?: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function weightedUseCount(memory: MemoryDecayCandidate, weights?: UseWeights): number;
|
|
15
|
+
export declare const decayUseCountCap = 20;
|
|
16
|
+
export declare const decayHalfLifeDays = 7;
|
|
17
|
+
export declare const decayDemotionThreshold = 0.5;
|
|
18
|
+
export declare const decayHoldOutDays = 30;
|
|
19
|
+
export declare function usageWeight(useCount: number | null | undefined, lastUsedAt: Date | string | null | undefined, now?: Date): number;
|
|
20
|
+
export declare function coldOnsetDays(useCount: number): number;
|
|
21
|
+
export declare function shouldDemoteOnUsage(memory: MemoryDecayCandidate, now?: Date, weights?: UseWeights): boolean;
|
|
22
|
+
//# sourceMappingURL=memory-decay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-decay.d.ts","sourceRoot":"","sources":["../../src/shared/memory-decay.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAI3F;AAED,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAC5C,GAAG,GAAE,IAAiB,GACrB,MAAM,CASR;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,GAAG,GAAE,IAAiB,EACtB,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAYT"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { msPerDay, parseMemoryDate } from "./memory-dates.js";
|
|
2
|
+
export const personalMemoryScope = "user";
|
|
3
|
+
export const preloadedUseWeight = 1;
|
|
4
|
+
export const citedUseWeight = 0;
|
|
5
|
+
export function weightedUseCount(memory, weights) {
|
|
6
|
+
const preloaded = Math.max(memory.memoryUseCount ?? 0, 0) * (weights?.preloaded ?? preloadedUseWeight);
|
|
7
|
+
const cited = Math.max(memory.memoryCiteCount ?? 0, 0) * (weights?.cited ?? citedUseWeight);
|
|
8
|
+
return preloaded + cited;
|
|
9
|
+
}
|
|
10
|
+
export const decayUseCountCap = 20;
|
|
11
|
+
export const decayHalfLifeDays = 7;
|
|
12
|
+
export const decayDemotionThreshold = 0.5;
|
|
13
|
+
export const decayHoldOutDays = 30;
|
|
14
|
+
export function usageWeight(useCount, lastUsedAt, now = new Date()) {
|
|
15
|
+
const uses = Math.min(Math.max(useCount ?? 0, 0), decayUseCountCap);
|
|
16
|
+
if (uses === 0)
|
|
17
|
+
return 0;
|
|
18
|
+
const lastUsed = parseMemoryDate(lastUsedAt);
|
|
19
|
+
if (!lastUsed)
|
|
20
|
+
return uses;
|
|
21
|
+
const days = Math.max((now.getTime() - lastUsed.getTime()) / msPerDay, 0);
|
|
22
|
+
return uses * Math.pow(0.5, days / decayHalfLifeDays);
|
|
23
|
+
}
|
|
24
|
+
export function coldOnsetDays(useCount) {
|
|
25
|
+
// Floor at the demotion threshold, not 1: a fractional weighted count is already below it at day 0,
|
|
26
|
+
// so clamping to 1 would report an onset the decay curve never had.
|
|
27
|
+
const uses = Math.min(Math.max(useCount, decayDemotionThreshold), decayUseCountCap);
|
|
28
|
+
return decayHalfLifeDays * Math.log2(uses / decayDemotionThreshold);
|
|
29
|
+
}
|
|
30
|
+
export function shouldDemoteOnUsage(memory, now = new Date(), weights) {
|
|
31
|
+
if (memory.scope !== personalMemoryScope)
|
|
32
|
+
return false;
|
|
33
|
+
const uses = weightedUseCount(memory, weights);
|
|
34
|
+
if (uses <= 0)
|
|
35
|
+
return false;
|
|
36
|
+
if (usageWeight(uses, memory.memoryLastUsedAt, now) >= decayDemotionThreshold)
|
|
37
|
+
return false;
|
|
38
|
+
const lastUsed = parseMemoryDate(memory.memoryLastUsedAt);
|
|
39
|
+
if (!lastUsed)
|
|
40
|
+
return false;
|
|
41
|
+
const daysSinceUse = (now.getTime() - lastUsed.getTime()) / msPerDay;
|
|
42
|
+
return daysSinceUse < coldOnsetDays(uses) + decayHoldOutDays;
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const memoryRedundancyThreshold = 0.6;
|
|
2
|
+
export declare const memoryDiversityCandidateMultiplier = 3;
|
|
3
|
+
export type DiversityCandidate = {
|
|
4
|
+
label?: string | null;
|
|
5
|
+
description?: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function memoryTokens(memory: DiversityCandidate): Set<string>;
|
|
8
|
+
export declare function jaccardSimilarity(a: Set<string>, b: Set<string>): number;
|
|
9
|
+
export declare function selectDiverseMemories<T extends DiversityCandidate>(candidates: readonly T[], limit: number, threshold?: number): T[];
|
|
10
|
+
//# sourceMappingURL=memory-diversity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-diversity.d.ts","sourceRoot":"","sources":["../../src/shared/memory-diversity.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,eAAO,MAAM,kCAAkC,IAAI,CAAC;AAEpD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAMF,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC,CAIpE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAMxE;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,kBAAkB,EAChE,UAAU,EAAE,SAAS,CAAC,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAkC,GAC5C,CAAC,EAAE,CAuBL"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const memoryRedundancyThreshold = 0.6;
|
|
2
|
+
export const memoryDiversityCandidateMultiplier = 3;
|
|
3
|
+
const tokenPattern = /[a-z0-9]+/g;
|
|
4
|
+
const minimumTokenLength = 3;
|
|
5
|
+
export function memoryTokens(memory) {
|
|
6
|
+
const text = `${memory.label ?? ""} ${memory.description ?? ""}`.toLowerCase();
|
|
7
|
+
const tokens = text.match(tokenPattern) ?? [];
|
|
8
|
+
return new Set(tokens.filter((t) => t.length >= minimumTokenLength));
|
|
9
|
+
}
|
|
10
|
+
export function jaccardSimilarity(a, b) {
|
|
11
|
+
if (a.size === 0 || b.size === 0)
|
|
12
|
+
return 0;
|
|
13
|
+
let shared = 0;
|
|
14
|
+
for (const token of a)
|
|
15
|
+
if (b.has(token))
|
|
16
|
+
shared += 1;
|
|
17
|
+
const union = a.size + b.size - shared;
|
|
18
|
+
return union === 0 ? 0 : shared / union;
|
|
19
|
+
}
|
|
20
|
+
export function selectDiverseMemories(candidates, limit, threshold = memoryRedundancyThreshold) {
|
|
21
|
+
if (limit <= 0)
|
|
22
|
+
return [];
|
|
23
|
+
if (candidates.length <= limit)
|
|
24
|
+
return [...candidates];
|
|
25
|
+
const tokens = candidates.map(memoryTokens);
|
|
26
|
+
const taken = [];
|
|
27
|
+
const skipped = [];
|
|
28
|
+
for (let i = 0; i < candidates.length && taken.length < limit; i += 1) {
|
|
29
|
+
const redundant = taken.some((j) => jaccardSimilarity(tokens[i] ?? new Set(), tokens[j] ?? new Set()) >= threshold);
|
|
30
|
+
if (redundant)
|
|
31
|
+
skipped.push(i);
|
|
32
|
+
else
|
|
33
|
+
taken.push(i);
|
|
34
|
+
}
|
|
35
|
+
for (const i of skipped) {
|
|
36
|
+
if (taken.length >= limit)
|
|
37
|
+
break;
|
|
38
|
+
taken.push(i);
|
|
39
|
+
}
|
|
40
|
+
return taken
|
|
41
|
+
.sort((a, b) => a - b)
|
|
42
|
+
.map((i) => candidates[i])
|
|
43
|
+
.filter((memory) => memory !== undefined);
|
|
44
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const entityHopLimit = 8;
|
|
2
|
+
export declare const entityLabelMatchLimit = 6;
|
|
3
|
+
export type EntityHopCandidate = {
|
|
4
|
+
aboutEntityIris?: readonly string[] | null;
|
|
5
|
+
};
|
|
6
|
+
export declare function collectAboutEntities(memories: readonly EntityHopCandidate[], limit?: number): string[];
|
|
7
|
+
export declare function withoutEntities(entityIris: readonly string[], exclude: readonly string[]): string[];
|
|
8
|
+
//# sourceMappingURL=memory-entity-recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-entity-recall.d.ts","sourceRoot":"","sources":["../../src/shared/memory-entity-recall.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,MAAM,MAAM,kBAAkB,GAAG;IAAE,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAEhF,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,EACvC,KAAK,GAAE,MAAuB,GAC7B,MAAM,EAAE,CAWV;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAGnG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const entityHopLimit = 8;
|
|
2
|
+
export const entityLabelMatchLimit = 6;
|
|
3
|
+
export function collectAboutEntities(memories, limit = entityHopLimit) {
|
|
4
|
+
const seen = new Set();
|
|
5
|
+
for (const memory of memories) {
|
|
6
|
+
for (const iri of memory.aboutEntityIris ?? []) {
|
|
7
|
+
if (seen.size >= limit)
|
|
8
|
+
return [...seen];
|
|
9
|
+
seen.add(iri);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [...seen];
|
|
13
|
+
}
|
|
14
|
+
export function withoutEntities(entityIris, exclude) {
|
|
15
|
+
const excluded = new Set(exclude);
|
|
16
|
+
return entityIris.filter((iri) => !excluded.has(iri));
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-importance.d.ts","sourceRoot":"","sources":["../../src/shared/memory-importance.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,MAAM,CAEvF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { clamp } from "ramda";
|
|
2
|
+
import { maxImportanceForVolatility } from "./memory-volatility.js";
|
|
3
|
+
export const defaultMemoryImportance = 3;
|
|
4
|
+
export function clampImportance(value) {
|
|
5
|
+
return clamp(1, 5, Math.round(value));
|
|
6
|
+
}
|
|
7
|
+
export function clampImportanceForVolatility(value, volatility) {
|
|
8
|
+
return Math.min(clampImportance(value), maxImportanceForVolatility(volatility));
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DiversityCandidate } from "./memory-diversity.js";
|
|
2
|
+
export declare const rankFusionConstant = 60;
|
|
3
|
+
export declare const maxKeywordTerms = 8;
|
|
4
|
+
export type KeywordCandidate = DiversityCandidate & {
|
|
5
|
+
iri: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function keywordTerms(text: string, limit?: number): string[];
|
|
8
|
+
export declare function keywordOverlap(memory: DiversityCandidate, terms: readonly string[]): number;
|
|
9
|
+
export declare function fuseRankings<T extends {
|
|
10
|
+
iri: string;
|
|
11
|
+
}>(lists: readonly (readonly T[])[]): T[];
|
|
12
|
+
export declare function fuseKeywordRanking<T extends KeywordCandidate>(semanticOrder: readonly T[], queryText: string): T[];
|
|
13
|
+
//# sourceMappingURL=memory-keyword-recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-keyword-recall.d.ts","sourceRoot":"","sources":["../../src/shared/memory-keyword-recall.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE3E,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAgGpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAwB,GAAG,MAAM,EAAE,CAKpF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAM3F;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAe7F;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,gBAAgB,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,CAalH"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { isPresent } from "@manta-eu/lib/present";
|
|
2
|
+
import { memoryTokens } from "./memory-diversity.js";
|
|
3
|
+
export const rankFusionConstant = 60;
|
|
4
|
+
export const maxKeywordTerms = 8;
|
|
5
|
+
// A term feeds a SPARQL CONTAINS that admits rows, so a stray function word like "the" would widen the pool to the
|
|
6
|
+
// entire store.
|
|
7
|
+
const stopWords = new Set([
|
|
8
|
+
"the",
|
|
9
|
+
"and",
|
|
10
|
+
"but",
|
|
11
|
+
"for",
|
|
12
|
+
"not",
|
|
13
|
+
"you",
|
|
14
|
+
"your",
|
|
15
|
+
"our",
|
|
16
|
+
"are",
|
|
17
|
+
"was",
|
|
18
|
+
"were",
|
|
19
|
+
"has",
|
|
20
|
+
"have",
|
|
21
|
+
"had",
|
|
22
|
+
"with",
|
|
23
|
+
"from",
|
|
24
|
+
"that",
|
|
25
|
+
"this",
|
|
26
|
+
"these",
|
|
27
|
+
"those",
|
|
28
|
+
"what",
|
|
29
|
+
"when",
|
|
30
|
+
"where",
|
|
31
|
+
"which",
|
|
32
|
+
"who",
|
|
33
|
+
"why",
|
|
34
|
+
"how",
|
|
35
|
+
"can",
|
|
36
|
+
"could",
|
|
37
|
+
"would",
|
|
38
|
+
"should",
|
|
39
|
+
"will",
|
|
40
|
+
"shall",
|
|
41
|
+
"may",
|
|
42
|
+
"might",
|
|
43
|
+
"must",
|
|
44
|
+
"there",
|
|
45
|
+
"their",
|
|
46
|
+
"them",
|
|
47
|
+
"they",
|
|
48
|
+
"its",
|
|
49
|
+
"his",
|
|
50
|
+
"her",
|
|
51
|
+
"him",
|
|
52
|
+
"she",
|
|
53
|
+
"here",
|
|
54
|
+
"into",
|
|
55
|
+
"onto",
|
|
56
|
+
"over",
|
|
57
|
+
"under",
|
|
58
|
+
"about",
|
|
59
|
+
"than",
|
|
60
|
+
"then",
|
|
61
|
+
"some",
|
|
62
|
+
"any",
|
|
63
|
+
"all",
|
|
64
|
+
"both",
|
|
65
|
+
"each",
|
|
66
|
+
"more",
|
|
67
|
+
"most",
|
|
68
|
+
"other",
|
|
69
|
+
"such",
|
|
70
|
+
"only",
|
|
71
|
+
"own",
|
|
72
|
+
"same",
|
|
73
|
+
"too",
|
|
74
|
+
"very",
|
|
75
|
+
"just",
|
|
76
|
+
"now",
|
|
77
|
+
"get",
|
|
78
|
+
"got",
|
|
79
|
+
"let",
|
|
80
|
+
"make",
|
|
81
|
+
"made",
|
|
82
|
+
"does",
|
|
83
|
+
"did",
|
|
84
|
+
"done",
|
|
85
|
+
"been",
|
|
86
|
+
"being",
|
|
87
|
+
"also",
|
|
88
|
+
"well",
|
|
89
|
+
"much",
|
|
90
|
+
"many",
|
|
91
|
+
"like",
|
|
92
|
+
"want",
|
|
93
|
+
"need",
|
|
94
|
+
"give",
|
|
95
|
+
"take",
|
|
96
|
+
"see",
|
|
97
|
+
]);
|
|
98
|
+
export function keywordTerms(text, limit = maxKeywordTerms) {
|
|
99
|
+
return [...memoryTokens({ label: text })]
|
|
100
|
+
.filter((token) => !stopWords.has(token))
|
|
101
|
+
.sort((a, b) => b.length - a.length || a.localeCompare(b))
|
|
102
|
+
.slice(0, limit);
|
|
103
|
+
}
|
|
104
|
+
export function keywordOverlap(memory, terms) {
|
|
105
|
+
if (!isPresent(terms))
|
|
106
|
+
return 0;
|
|
107
|
+
const tokens = memoryTokens(memory);
|
|
108
|
+
let hits = 0;
|
|
109
|
+
for (const term of terms)
|
|
110
|
+
if (tokens.has(term))
|
|
111
|
+
hits += 1;
|
|
112
|
+
return hits;
|
|
113
|
+
}
|
|
114
|
+
export function fuseRankings(lists) {
|
|
115
|
+
const scores = new Map();
|
|
116
|
+
const byIri = new Map();
|
|
117
|
+
for (const list of lists) {
|
|
118
|
+
list.forEach((item, rank) => {
|
|
119
|
+
scores.set(item.iri, (scores.get(item.iri) ?? 0) + 1 / (rankFusionConstant + rank));
|
|
120
|
+
if (!byIri.has(item.iri))
|
|
121
|
+
byIri.set(item.iri, item);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return [...scores.entries()]
|
|
125
|
+
.sort(([iriA, scoreA], [iriB, scoreB]) => scoreB - scoreA || iriA.localeCompare(iriB))
|
|
126
|
+
.map(([iri]) => byIri.get(iri))
|
|
127
|
+
.filter((item) => item !== undefined);
|
|
128
|
+
}
|
|
129
|
+
export function fuseKeywordRanking(semanticOrder, queryText) {
|
|
130
|
+
const terms = keywordTerms(queryText);
|
|
131
|
+
if (!isPresent(terms) || !isPresent(semanticOrder))
|
|
132
|
+
return [...semanticOrder];
|
|
133
|
+
const keywordOrder = semanticOrder
|
|
134
|
+
.map((memory) => ({ memory, hits: keywordOverlap(memory, terms) }))
|
|
135
|
+
.filter((scored) => scored.hits > 0)
|
|
136
|
+
.sort((a, b) => b.hits - a.hits)
|
|
137
|
+
.map((scored) => scored.memory);
|
|
138
|
+
if (!isPresent(keywordOrder))
|
|
139
|
+
return [...semanticOrder];
|
|
140
|
+
return fuseRankings([semanticOrder, keywordOrder]);
|
|
141
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const memoryKinds: readonly ["preference", "fact", "objective", "context"];
|
|
2
|
+
export type MemoryKind = (typeof memoryKinds)[number];
|
|
3
|
+
export declare const memoryKindIris: Record<MemoryKind, string>;
|
|
4
|
+
export type MemoryKindIri = (typeof memoryKindIris)[MemoryKind];
|
|
5
|
+
export declare function isKindIri(iri: string): boolean;
|
|
6
|
+
export declare function kindIriToKind(iri: string): MemoryKind | null;
|
|
7
|
+
export declare function kindIriToLabel(iri: string): string | null;
|
|
8
|
+
export declare function kindToKindIri(kind: MemoryKind): string;
|
|
9
|
+
//# sourceMappingURL=memory-kind-iris.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-kind-iris.d.ts","sourceRoot":"","sources":["../../src/shared/memory-kind-iris.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,yDAA0D,CAAC;AACnF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAItD,eAAO,MAAM,cAAc,EAEtB,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEhC,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,UAAU,CAAC,CAAC;AAQhE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAE5D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGzD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { vocabBase } from "@manta-eu/ldo/realm";
|
|
2
|
+
// GraphQL MemoryKind, backend valid-kind?, and KG sh:in must stay in sync with this.
|
|
3
|
+
export const memoryKinds = ["preference", "fact", "objective", "context"];
|
|
4
|
+
const memoryKindIriBase = `${vocabBase}MemoryKind_`;
|
|
5
|
+
export const memoryKindIris = Object.fromEntries(memoryKinds.map((kind) => [kind, `${memoryKindIriBase}${kind}`]));
|
|
6
|
+
const iriToKind = new Map(memoryKinds.map((kind) => [memoryKindIris[kind], kind]));
|
|
7
|
+
function capitalize(value) {
|
|
8
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
9
|
+
}
|
|
10
|
+
export function isKindIri(iri) {
|
|
11
|
+
return iriToKind.has(iri);
|
|
12
|
+
}
|
|
13
|
+
export function kindIriToKind(iri) {
|
|
14
|
+
return iriToKind.get(iri) ?? null;
|
|
15
|
+
}
|
|
16
|
+
export function kindIriToLabel(iri) {
|
|
17
|
+
const kind = iriToKind.get(iri);
|
|
18
|
+
return kind ? capitalize(kind) : null;
|
|
19
|
+
}
|
|
20
|
+
export function kindToKindIri(kind) {
|
|
21
|
+
return memoryKindIris[kind];
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseMemoryDate } from "./memory-dates.js";
|
|
2
|
+
import { type UseWeights } from "./memory-decay.js";
|
|
3
|
+
export { parseMemoryDate };
|
|
4
|
+
export type { UseWeights };
|
|
5
|
+
export declare const memoryPreloadConfidenceThreshold = 0.75;
|
|
6
|
+
export declare const memoryPreloadImportanceThreshold = 4;
|
|
7
|
+
export declare const memorySearchImportanceThreshold = 2;
|
|
8
|
+
export declare const memoryPreloadRowLimit = 20;
|
|
9
|
+
export declare const companyMemoryScope = "company";
|
|
10
|
+
export declare const validFromWorthShowingDays = 2;
|
|
11
|
+
export declare const trustedUntilExpiringSoonDays = 7;
|
|
12
|
+
export type MemoryPreloadCandidate = {
|
|
13
|
+
importance: number;
|
|
14
|
+
confidence?: number | null;
|
|
15
|
+
memoryValidUntil?: Date | string | null;
|
|
16
|
+
memoryValidFrom?: Date | string | null;
|
|
17
|
+
memoryTrustedUntil?: Date | string | null;
|
|
18
|
+
memoryUseCount?: number | null;
|
|
19
|
+
memoryCiteCount?: number | null;
|
|
20
|
+
memoryLastUsedAt?: Date | string | null;
|
|
21
|
+
scope?: string | null;
|
|
22
|
+
supersededBy?: string | null;
|
|
23
|
+
};
|
|
24
|
+
export type MemoryPreloadExclusion = "archived" | "importance" | "confidence" | "stale" | "expired" | "scheduled" | "cold";
|
|
25
|
+
export declare function isPastTrustedUntilAt(memoryTrustedUntil: Date | string | null | undefined, now: Date): boolean;
|
|
26
|
+
export declare function isTrustedUntilExpiringSoon(memoryTrustedUntil: Date | string | null | undefined, now: Date): boolean;
|
|
27
|
+
export declare function isMemoryArchived(memory: MemoryPreloadCandidate): boolean;
|
|
28
|
+
export declare function isNeverUsed(memory: MemoryPreloadCandidate, now?: Date): boolean;
|
|
29
|
+
export declare function needsTrustReview(memory: MemoryPreloadCandidate, now?: Date): boolean;
|
|
30
|
+
export declare function isMemorySearchable(memory: MemoryPreloadCandidate): boolean;
|
|
31
|
+
export declare function memoryPreloadQueryExclusions(memory: MemoryPreloadCandidate, now?: Date): MemoryPreloadExclusion[];
|
|
32
|
+
export declare function isMemoryQueryGateEligible(memory: MemoryPreloadCandidate, now?: Date): boolean;
|
|
33
|
+
export declare function memoryPreloadExclusions(memory: MemoryPreloadCandidate, now?: Date, weights?: UseWeights): MemoryPreloadExclusion[];
|
|
34
|
+
export declare function isMemoryPreloaded(memory: MemoryPreloadCandidate, now?: Date, weights?: UseWeights): boolean;
|
|
35
|
+
export declare function describeMemoryPreloadExclusions(memory: MemoryPreloadCandidate, exclusions: MemoryPreloadExclusion[]): string;
|
|
36
|
+
export declare function describeMemoryPreload(memory: MemoryPreloadCandidate, now?: Date): string;
|
|
37
|
+
//# sourceMappingURL=memory-preload-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-preload-gate.d.ts","sourceRoot":"","sources":["../../src/shared/memory-preload-gate.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAClD,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gBAAgB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,eAAe,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,kBAAkB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IAC1C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,OAAO,GACP,SAAS,GACT,WAAW,GACX,MAAM,CAAC;AAEX,wBAAgB,oBAAoB,CAAC,kBAAkB,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAG7G;AAID,wBAAgB,0BAA0B,CAAC,kBAAkB,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAInH;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAExE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,sBAAsB,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAE3F;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAMhG;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAE1E;AAGD,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,sBAAsB,EAC9B,GAAG,GAAE,IAAiB,GACrB,sBAAsB,EAAE,CAoB1B;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAEzG;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,sBAAsB,EAC9B,GAAG,GAAE,IAAiB,EACtB,OAAO,CAAC,EAAE,UAAU,GACnB,sBAAsB,EAAE,CAK1B;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,GAAG,GAAE,IAAiB,EACtB,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAET;AAYD,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,sBAAsB,EAC9B,UAAU,EAAE,sBAAsB,EAAE,GACnC,MAAM,CASR;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAEpG"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isPresent } from "@manta-eu/lib/present";
|
|
2
|
+
import { msPerDay, parseMemoryDate } from "./memory-dates.js";
|
|
3
|
+
import { shouldDemoteOnUsage } from "./memory-decay.js";
|
|
4
|
+
export { parseMemoryDate };
|
|
5
|
+
export const memoryPreloadConfidenceThreshold = 0.75;
|
|
6
|
+
export const memoryPreloadImportanceThreshold = 4;
|
|
7
|
+
export const memorySearchImportanceThreshold = 2;
|
|
8
|
+
export const memoryPreloadRowLimit = 20;
|
|
9
|
+
export const companyMemoryScope = "company";
|
|
10
|
+
export const validFromWorthShowingDays = 2;
|
|
11
|
+
export const trustedUntilExpiringSoonDays = 7;
|
|
12
|
+
export function isPastTrustedUntilAt(memoryTrustedUntil, now) {
|
|
13
|
+
const horizon = parseMemoryDate(memoryTrustedUntil);
|
|
14
|
+
return horizon != null && horizon <= now;
|
|
15
|
+
}
|
|
16
|
+
// Elapsed time, not calendar days: this module runs in the browser too, where the local zone would
|
|
17
|
+
// shift the boundary by a day either side of UTC.
|
|
18
|
+
export function isTrustedUntilExpiringSoon(memoryTrustedUntil, now) {
|
|
19
|
+
const horizon = parseMemoryDate(memoryTrustedUntil);
|
|
20
|
+
if (horizon == null || horizon <= now)
|
|
21
|
+
return false;
|
|
22
|
+
return horizon.getTime() - now.getTime() <= trustedUntilExpiringSoonDays * msPerDay;
|
|
23
|
+
}
|
|
24
|
+
export function isMemoryArchived(memory) {
|
|
25
|
+
return isPresent(memory.supersededBy);
|
|
26
|
+
}
|
|
27
|
+
export function isNeverUsed(memory, now = new Date()) {
|
|
28
|
+
return isMemoryPreloaded(memory, now) && (memory.memoryUseCount ?? 0) + (memory.memoryCiteCount ?? 0) === 0;
|
|
29
|
+
}
|
|
30
|
+
export function needsTrustReview(memory, now = new Date()) {
|
|
31
|
+
if (isMemoryArchived(memory))
|
|
32
|
+
return false;
|
|
33
|
+
if (memory.memoryValidUntil)
|
|
34
|
+
return false;
|
|
35
|
+
return (isPastTrustedUntilAt(memory.memoryTrustedUntil, now) || isTrustedUntilExpiringSoon(memory.memoryTrustedUntil, now));
|
|
36
|
+
}
|
|
37
|
+
export function isMemorySearchable(memory) {
|
|
38
|
+
return !isMemoryArchived(memory) && memory.importance >= memorySearchImportanceThreshold;
|
|
39
|
+
}
|
|
40
|
+
// Mirrors the SPARQL pre-load gate; "cold" stays client-side since decay is weighted per caller.
|
|
41
|
+
export function memoryPreloadQueryExclusions(memory, now = new Date()) {
|
|
42
|
+
const exclusions = [];
|
|
43
|
+
if (isMemoryArchived(memory))
|
|
44
|
+
exclusions.push("archived");
|
|
45
|
+
if (memory.importance < memoryPreloadImportanceThreshold)
|
|
46
|
+
exclusions.push("importance");
|
|
47
|
+
if (memory.scope !== companyMemoryScope &&
|
|
48
|
+
memory.confidence != null &&
|
|
49
|
+
memory.confidence < memoryPreloadConfidenceThreshold) {
|
|
50
|
+
exclusions.push("confidence");
|
|
51
|
+
}
|
|
52
|
+
if (isPastTrustedUntilAt(memory.memoryTrustedUntil, now))
|
|
53
|
+
exclusions.push("stale");
|
|
54
|
+
// Mirrors liveContextMemoryDateFilter: the query drops on all three date predicates, not just trust.
|
|
55
|
+
const validUntil = parseMemoryDate(memory.memoryValidUntil);
|
|
56
|
+
if (validUntil != null && validUntil <= now)
|
|
57
|
+
exclusions.push("expired");
|
|
58
|
+
const validFrom = parseMemoryDate(memory.memoryValidFrom);
|
|
59
|
+
if (validFrom != null && validFrom > now)
|
|
60
|
+
exclusions.push("scheduled");
|
|
61
|
+
return exclusions;
|
|
62
|
+
}
|
|
63
|
+
export function isMemoryQueryGateEligible(memory, now = new Date()) {
|
|
64
|
+
return !isPresent(memoryPreloadQueryExclusions(memory, now));
|
|
65
|
+
}
|
|
66
|
+
export function memoryPreloadExclusions(memory, now = new Date(), weights) {
|
|
67
|
+
const exclusions = memoryPreloadQueryExclusions(memory, now);
|
|
68
|
+
if (shouldDemoteOnUsage(memory, now, weights))
|
|
69
|
+
exclusions.push("cold");
|
|
70
|
+
return exclusions;
|
|
71
|
+
}
|
|
72
|
+
export function isMemoryPreloaded(memory, now = new Date(), weights) {
|
|
73
|
+
return !isPresent(memoryPreloadExclusions(memory, now, weights));
|
|
74
|
+
}
|
|
75
|
+
const exclusionReasons = {
|
|
76
|
+
archived: "it was replaced by a newer memory",
|
|
77
|
+
importance: `importance is below ${memoryPreloadImportanceThreshold} (High)`,
|
|
78
|
+
confidence: `confidence is below ${memoryPreloadConfidenceThreshold} — it has not been reviewed`,
|
|
79
|
+
stale: "it is no longer trusted and needs re-confirming",
|
|
80
|
+
expired: "its expiry date has passed",
|
|
81
|
+
scheduled: "it does not take effect until a later date",
|
|
82
|
+
cold: "nothing has used it in a long time, so it no longer earns a place in every prompt",
|
|
83
|
+
};
|
|
84
|
+
export function describeMemoryPreloadExclusions(memory, exclusions) {
|
|
85
|
+
if (!isPresent(exclusions)) {
|
|
86
|
+
return `In your assistant's context, up to ${memoryPreloadRowLimit} per scope on any one turn (most relevant first).`;
|
|
87
|
+
}
|
|
88
|
+
const reasons = exclusions.map((exclusion) => exclusionReasons[exclusion]).join("; ");
|
|
89
|
+
return isMemorySearchable(memory)
|
|
90
|
+
? `Not in context: ${reasons}. Still retrievable with searchMemories.`
|
|
91
|
+
: `Not in context: ${reasons}. Not retrievable with searchMemories either.`;
|
|
92
|
+
}
|
|
93
|
+
export function describeMemoryPreload(memory, now = new Date()) {
|
|
94
|
+
return describeMemoryPreloadExclusions(memory, memoryPreloadExclusions(memory, now));
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-sources.d.ts","sourceRoot":"","sources":["../../src/shared/memory-sources.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,QAA8B,CAAC;AAElE,eAAO,MAAM,8BAA8B,QAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-teams.d.ts","sourceRoot":"","sources":["../../src/shared/memory-teams.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,CAElG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const charsPerTokenEstimate = 4;
|
|
2
|
+
export declare const memoryPreloadRowTokenAllowance = 120;
|
|
3
|
+
export declare const memoryPreloadTokenBudgetPerBlock: number;
|
|
4
|
+
export declare const memoryPreloadBlockCount = 3;
|
|
5
|
+
export declare const memoryPreloadTokenBudgetTotal: number;
|
|
6
|
+
export declare function estimateTokens(text: string): number;
|
|
7
|
+
export declare function packToBudget<T>(items: readonly T[], cost: (item: T) => number, budget: number): T[];
|
|
8
|
+
//# sourceMappingURL=memory-token-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-token-budget.d.ts","sourceRoot":"","sources":["../../src/shared/memory-token-budget.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAElD,eAAO,MAAM,gCAAgC,QAAyD,CAAC;AAEvG,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,eAAO,MAAM,6BAA6B,QAA6D,CAAC;AAExG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAYnG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isPresent } from "@manta-eu/lib/present";
|
|
2
|
+
import { memoryPreloadRowLimit } from "./memory-preload-gate.js";
|
|
3
|
+
// 4 chars/token approximates English prose; the serving model's real tokenizer is not available in the Worker.
|
|
4
|
+
export const charsPerTokenEstimate = 4;
|
|
5
|
+
export const memoryPreloadRowTokenAllowance = 120;
|
|
6
|
+
export const memoryPreloadTokenBudgetPerBlock = memoryPreloadRowLimit * memoryPreloadRowTokenAllowance;
|
|
7
|
+
export const memoryPreloadBlockCount = 3;
|
|
8
|
+
export const memoryPreloadTokenBudgetTotal = memoryPreloadTokenBudgetPerBlock * memoryPreloadBlockCount;
|
|
9
|
+
export function estimateTokens(text) {
|
|
10
|
+
return Math.ceil(text.length / charsPerTokenEstimate);
|
|
11
|
+
}
|
|
12
|
+
export function packToBudget(items, cost, budget) {
|
|
13
|
+
const kept = [];
|
|
14
|
+
let spent = 0;
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
const itemCost = cost(item);
|
|
17
|
+
if (isPresent(kept) && spent + itemCost > budget)
|
|
18
|
+
continue;
|
|
19
|
+
kept.push(item);
|
|
20
|
+
spent += itemCost;
|
|
21
|
+
}
|
|
22
|
+
return kept;
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const memoryVolatilities: readonly ["stable", "slow", "volatile"];
|
|
2
|
+
export type MemoryVolatility = (typeof memoryVolatilities)[number];
|
|
3
|
+
export type MemoryVolatilityRule = {
|
|
4
|
+
trustDays: number | null;
|
|
5
|
+
maxImportance: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const volatilityRules: Record<MemoryVolatility, MemoryVolatilityRule>;
|
|
8
|
+
export declare const defaultMemoryVolatility: MemoryVolatility;
|
|
9
|
+
export declare function isMemoryVolatility(value: unknown): value is MemoryVolatility;
|
|
10
|
+
export declare function normalizeVolatility(value: unknown): MemoryVolatility;
|
|
11
|
+
export declare function volatilityTrustDays(volatility: unknown): number | null;
|
|
12
|
+
export declare function maxImportanceForVolatility(volatility: unknown): number;
|
|
13
|
+
export declare const volatilityInferenceSlack = 1.5;
|
|
14
|
+
export declare function inferVolatility(memoryTrustedUntil: Date | string | null | undefined, since: Date | string | null | undefined): MemoryVolatility;
|
|
15
|
+
export type VolatilityTrace = {
|
|
16
|
+
memoryTrustedUntil?: Date | string | null;
|
|
17
|
+
memoryValidUntil?: Date | string | null;
|
|
18
|
+
extractedAt?: Date | string | null;
|
|
19
|
+
};
|
|
20
|
+
export declare function isDeadlineDerivedHorizon(memoryTrustedUntil: Date | string | null | undefined, memoryValidUntil: Date | string | null | undefined): boolean;
|
|
21
|
+
export declare function importanceCeilingFor(memory: VolatilityTrace): number;
|
|
22
|
+
export declare function capHorizonByDeadline(horizon: string | null, memoryValidUntil: string | null, now?: Date): string | null;
|
|
23
|
+
export declare function resolveTrustedUntil(volatility: unknown, memoryValidUntil: string | null, now?: Date): string | null;
|
|
24
|
+
//# sourceMappingURL=memory-volatility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-volatility.d.ts","sourceRoot":"","sources":["../../src/shared/memory-volatility.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,yCAA0C,CAAC;AAE1E,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAAG;IAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,gBAAgB,EAAE,oBAAoB,CAI1E,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,gBAAyB,CAAC;AAEhE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAEpE;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAEtE;AAED,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAEtE;AAED,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,wBAAgB,eAAe,CAC7B,kBAAkB,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACpD,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,gBAAgB,CAUlB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IAC1C,gBAAgB,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,kBAAkB,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACpD,gBAAgB,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GACjD,OAAO,CAIT;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAIpE;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,GAAG,GAAE,IAAiB,GACrB,MAAM,GAAG,IAAI,CAKf;AAED,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,OAAO,EACnB,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,GAAG,GAAE,IAAiB,GACrB,MAAM,GAAG,IAAI,CAIf"}
|