pythx-cli 0.0.3 → 0.0.4
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/cli.js +641 -14
- package/package.json +11 -3
- package/.turbo/turbo-build.log +0 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -42
- package/dist/cli.d.ts +0 -2
- package/dist/components/detail-panel.d.ts +0 -6
- package/dist/components/detail-panel.js +0 -35
- package/dist/components/entity-row.d.ts +0 -13
- package/dist/components/entity-row.js +0 -47
- package/dist/components/header.d.ts +0 -6
- package/dist/components/header.js +0 -17
- package/dist/components/status-bar.d.ts +0 -1
- package/dist/components/status-bar.js +0 -6
- package/dist/hooks/use-live-data.d.ts +0 -8
- package/dist/hooks/use-live-data.js +0 -75
- package/src/app.tsx +0 -95
- package/src/cli.tsx +0 -38
- package/src/components/detail-panel.tsx +0 -81
- package/src/components/entity-row.tsx +0 -83
- package/src/components/header.tsx +0 -48
- package/src/components/status-bar.tsx +0 -26
- package/src/hooks/use-live-data.ts +0 -86
- package/tsconfig.json +0 -13
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from "react";
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_ENTITIES,
|
|
4
|
-
getProvider,
|
|
5
|
-
classifyPosts,
|
|
6
|
-
aggregate,
|
|
7
|
-
} from "@pythx/core";
|
|
8
|
-
import type { EntityAnalysis } from "@pythx/core";
|
|
9
|
-
|
|
10
|
-
const POLL_INTERVAL = 60_000;
|
|
11
|
-
|
|
12
|
-
export function useLiveData(apiUrl?: string) {
|
|
13
|
-
const [data, setData] = useState<EntityAnalysis[]>([]);
|
|
14
|
-
const [loading, setLoading] = useState(true);
|
|
15
|
-
const [error, setError] = useState<string | null>(null);
|
|
16
|
-
const [lastUpdated, setLastUpdated] = useState<Date | null>(null);
|
|
17
|
-
|
|
18
|
-
const fetchViaApi = useCallback(async () => {
|
|
19
|
-
if (!apiUrl) return;
|
|
20
|
-
try {
|
|
21
|
-
const res = await fetch(`${apiUrl}/api/compare`, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: { "Content-Type": "application/json" },
|
|
24
|
-
body: JSON.stringify({
|
|
25
|
-
entityIds: DEFAULT_ENTITIES.map((e) => e.id),
|
|
26
|
-
count: 50,
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
const json = (await res.json()) as { success: boolean; data?: EntityAnalysis[]; error?: string };
|
|
30
|
-
if (json.success && json.data) {
|
|
31
|
-
setData(json.data);
|
|
32
|
-
setLastUpdated(new Date());
|
|
33
|
-
setError(null);
|
|
34
|
-
} else {
|
|
35
|
-
setError(json.error ?? "API error");
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
setError(err instanceof Error ? err.message : "Fetch failed");
|
|
39
|
-
} finally {
|
|
40
|
-
setLoading(false);
|
|
41
|
-
}
|
|
42
|
-
}, [apiUrl]);
|
|
43
|
-
|
|
44
|
-
const fetchDirect = useCallback(async () => {
|
|
45
|
-
try {
|
|
46
|
-
const results: EntityAnalysis[] = [];
|
|
47
|
-
|
|
48
|
-
for (const entity of DEFAULT_ENTITIES) {
|
|
49
|
-
const allClassified = [];
|
|
50
|
-
|
|
51
|
-
for (const sq of entity.queries) {
|
|
52
|
-
const provider = getProvider(sq.source);
|
|
53
|
-
const posts = await provider.fetchPosts(sq.query, { count: 50 });
|
|
54
|
-
const classified = await classifyPosts(posts, provider.getModelId());
|
|
55
|
-
allClassified.push(...classified);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const snapshot = aggregate(allClassified);
|
|
59
|
-
results.push({
|
|
60
|
-
entity,
|
|
61
|
-
snapshot,
|
|
62
|
-
posts: allClassified,
|
|
63
|
-
fetchedAt: new Date().toISOString(),
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setData(results);
|
|
68
|
-
setLastUpdated(new Date());
|
|
69
|
-
setError(null);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
setError(err instanceof Error ? err.message : "Analysis failed");
|
|
72
|
-
} finally {
|
|
73
|
-
setLoading(false);
|
|
74
|
-
}
|
|
75
|
-
}, []);
|
|
76
|
-
|
|
77
|
-
const fetchData = apiUrl ? fetchViaApi : fetchDirect;
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
fetchData();
|
|
81
|
-
const interval = setInterval(fetchData, POLL_INTERVAL);
|
|
82
|
-
return () => clearInterval(interval);
|
|
83
|
-
}, [fetchData]);
|
|
84
|
-
|
|
85
|
-
return { data, loading, error, lastUpdated, refresh: fetchData };
|
|
86
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"jsx": "react-jsx",
|
|
5
|
-
"lib": ["ES2022"],
|
|
6
|
-
"types": ["node"],
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"rootDir": "./src"
|
|
10
|
-
},
|
|
11
|
-
"include": ["src"],
|
|
12
|
-
"exclude": ["node_modules", "dist"]
|
|
13
|
-
}
|