@pyxmate/memory 0.0.1-beta

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/react.mjs ADDED
@@ -0,0 +1,154 @@
1
+ import {
2
+ DashboardClient,
3
+ Poller,
4
+ analyzeConsolidationLog,
5
+ computeMetrics,
6
+ computeTypeDistribution,
7
+ enrichHealth,
8
+ formatBytes,
9
+ formatUptime,
10
+ toD3ForceFormat,
11
+ toGraphologyFormat,
12
+ transformGraphData,
13
+ unreachableHealth
14
+ } from "./chunk-EDIYGMT2.mjs";
15
+ import "./chunk-Q4QIILKH.mjs";
16
+
17
+ // ../dashboard/src/hooks/use-consolidation-log.ts
18
+ import { useCallback as useCallback2, useMemo } from "react";
19
+
20
+ // ../dashboard/src/hooks/use-polling.ts
21
+ import { useCallback, useEffect, useRef, useState } from "react";
22
+ function usePolling(fetcher, options) {
23
+ const { intervalMs, enabled = true } = options;
24
+ const [data, setData] = useState(null);
25
+ const [error, setError] = useState(null);
26
+ const [isLoading, setIsLoading] = useState(enabled);
27
+ const [lastUpdated, setLastUpdated] = useState(null);
28
+ const fetchIdRef = useRef(0);
29
+ const poll = useCallback(async () => {
30
+ fetchIdRef.current++;
31
+ const id = fetchIdRef.current;
32
+ setIsLoading(true);
33
+ try {
34
+ const result = await fetcher();
35
+ if (id !== fetchIdRef.current) return;
36
+ setData(result);
37
+ setError(null);
38
+ setLastUpdated(/* @__PURE__ */ new Date());
39
+ } catch (err) {
40
+ if (id !== fetchIdRef.current) return;
41
+ setError(err instanceof Error ? err : new Error(String(err)));
42
+ } finally {
43
+ if (id === fetchIdRef.current) {
44
+ setIsLoading(false);
45
+ }
46
+ }
47
+ }, [fetcher]);
48
+ useEffect(() => {
49
+ if (!enabled) return;
50
+ void poll();
51
+ if (intervalMs <= 0) return;
52
+ const timer = setInterval(() => void poll(), intervalMs);
53
+ return () => clearInterval(timer);
54
+ }, [poll, intervalMs, enabled]);
55
+ const refetch = useCallback(() => {
56
+ void poll();
57
+ }, [poll]);
58
+ return { data, error, isLoading, lastUpdated, refetch };
59
+ }
60
+
61
+ // ../dashboard/src/hooks/use-consolidation-log.ts
62
+ function useConsolidationLog(serverUrl, limit = 20, intervalMs = 3e4) {
63
+ const client = useMemo(() => new DashboardClient(serverUrl), [serverUrl]);
64
+ const fetcher = useCallback2(async () => {
65
+ const entries = await client.consolidationLog(limit);
66
+ return analyzeConsolidationLog(entries);
67
+ }, [client, limit]);
68
+ return usePolling(fetcher, { intervalMs });
69
+ }
70
+
71
+ // ../dashboard/src/hooks/use-knowledge-graph.ts
72
+ import { useCallback as useCallback3, useMemo as useMemo2 } from "react";
73
+ function useKnowledgeGraph(serverUrl, opts = {}) {
74
+ const { intervalMs = 3e4, limit = 50, minWeight, maxNodes } = opts;
75
+ const client = useMemo2(() => new DashboardClient(serverUrl), [serverUrl]);
76
+ const stableTransformOpts = useMemo2(
77
+ () => ({ minWeight, maxNodes }),
78
+ [minWeight, maxNodes]
79
+ );
80
+ const fetcher = useCallback3(async () => {
81
+ const { nodes, relationships } = await client.graphFull(limit);
82
+ return transformGraphData(nodes, relationships, stableTransformOpts);
83
+ }, [client, limit, stableTransformOpts]);
84
+ return usePolling(fetcher, { intervalMs });
85
+ }
86
+
87
+ // ../dashboard/src/hooks/use-memory-entries.ts
88
+ import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
89
+ function useMemoryEntries(serverUrl, filters = {}, intervalMs = 0) {
90
+ const client = useMemo3(() => new DashboardClient(serverUrl), [serverUrl]);
91
+ const { page, limit, type, agentId, query } = filters;
92
+ const fetcher = useCallback4(
93
+ () => client.listEntriesPaginated({ page, limit, type, agentId, query }),
94
+ [client, page, limit, type, agentId, query]
95
+ );
96
+ return usePolling(fetcher, {
97
+ intervalMs: intervalMs ?? 3e4
98
+ });
99
+ }
100
+
101
+ // ../dashboard/src/hooks/use-memory-health.ts
102
+ import { useCallback as useCallback5, useMemo as useMemo4 } from "react";
103
+ function useMemoryHealth(serverUrl, intervalMs = 1e4) {
104
+ const client = useMemo4(() => new DashboardClient(serverUrl), [serverUrl]);
105
+ const fetcher = useCallback5(async () => {
106
+ try {
107
+ const raw = await client.fetchHealthRaw();
108
+ return enrichHealth(raw);
109
+ } catch (err) {
110
+ return unreachableHealth(err instanceof Error ? err : new Error(String(err)));
111
+ }
112
+ }, [client]);
113
+ return usePolling(fetcher, { intervalMs });
114
+ }
115
+
116
+ // ../dashboard/src/hooks/use-memory-stats.ts
117
+ import { useCallback as useCallback6, useMemo as useMemo5 } from "react";
118
+ function useMemoryStats(serverUrl, intervalMs = 5e3) {
119
+ const client = useMemo5(() => new DashboardClient(serverUrl), [serverUrl]);
120
+ const fetcher = useCallback6(() => client.stats(), [client]);
121
+ return usePolling(fetcher, { intervalMs });
122
+ }
123
+
124
+ // ../dashboard/src/hooks/use-type-distribution.ts
125
+ import { useCallback as useCallback7, useMemo as useMemo6 } from "react";
126
+ function useTypeDistribution(serverUrl, intervalMs = 15e3) {
127
+ const client = useMemo6(() => new DashboardClient(serverUrl), [serverUrl]);
128
+ const fetcher = useCallback7(async () => {
129
+ const entries = await client.listEntries({ limit: 100 });
130
+ return computeTypeDistribution(entries);
131
+ }, [client]);
132
+ return usePolling(fetcher, { intervalMs });
133
+ }
134
+ export {
135
+ DashboardClient,
136
+ Poller,
137
+ analyzeConsolidationLog,
138
+ computeMetrics,
139
+ computeTypeDistribution,
140
+ enrichHealth,
141
+ formatBytes,
142
+ formatUptime,
143
+ toD3ForceFormat,
144
+ toGraphologyFormat,
145
+ transformGraphData,
146
+ unreachableHealth,
147
+ useConsolidationLog,
148
+ useKnowledgeGraph,
149
+ useMemoryEntries,
150
+ useMemoryHealth,
151
+ useMemoryStats,
152
+ usePolling,
153
+ useTypeDistribution
154
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@pyxmate/memory",
3
+ "version": "0.0.1-beta",
4
+ "type": "module",
5
+ "description": "SDK for pyx-memory — Memory as a Service for AI agents",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "keywords": [
9
+ "memory",
10
+ "ai",
11
+ "rag",
12
+ "agents",
13
+ "knowledge-graph",
14
+ "vector-search",
15
+ "maas"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/fysoul17/pyx-memory.git",
20
+ "directory": "packages/sdk"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.mjs",
25
+ "types": "./dist/index.d.ts"
26
+ },
27
+ "./dashboard": {
28
+ "import": "./dist/dashboard.mjs",
29
+ "types": "./dist/dashboard.d.ts"
30
+ },
31
+ "./react": {
32
+ "import": "./dist/react.mjs",
33
+ "types": "./dist/react.d.ts"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "typecheck": "tsc --noEmit",
44
+ "clean": "rm -rf dist node_modules .turbo"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=18.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "react": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@types/react": "^19.0.0",
56
+ "react": "^19.2.4",
57
+ "tsup": "^8.4.0"
58
+ }
59
+ }