@sentry/junior-memory 0.190.0 → 0.192.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/dist/agent.d.ts +2 -2
- package/dist/api.d.ts +18 -3
- package/dist/index.js +62 -4
- package/dist/index.js.map +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/viewer.d.ts +6 -0
- package/package.json +3 -3
- package/src/api.ts +30 -3
- package/src/operational-report.ts +2 -1
- package/src/viewer.ts +48 -0
package/dist/store.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ export declare const memorySupersessionInputSchema: z.ZodObject<{
|
|
|
118
118
|
eventType: z.ZodString;
|
|
119
119
|
identifier: z.ZodString;
|
|
120
120
|
namespace: z.ZodString;
|
|
121
|
-
}, z.core.$strict>], "kind"
|
|
121
|
+
}, z.core.$strict>], "kind">, unknown>;
|
|
122
122
|
userId: z.ZodOptional<z.ZodString>;
|
|
123
123
|
}, z.core.$strict>;
|
|
124
124
|
}, z.core.$strict>;
|
package/dist/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare const memoryRuntimeContextSchema: z.ZodObject<{
|
|
|
64
64
|
eventType: z.ZodString;
|
|
65
65
|
identifier: z.ZodString;
|
|
66
66
|
namespace: z.ZodString;
|
|
67
|
-
}, z.core.$strict>], "kind"
|
|
67
|
+
}, z.core.$strict>], "kind">, unknown>;
|
|
68
68
|
userId: z.ZodOptional<z.ZodString>;
|
|
69
69
|
}, z.core.$strict>;
|
|
70
70
|
export type MemoryRuntimeContext = z.output<typeof memoryRuntimeContextSchema>;
|
package/dist/viewer.d.ts
CHANGED
|
@@ -82,4 +82,10 @@ export declare function getMemoryTimeline(db: MemoryDb, userId: string, days: nu
|
|
|
82
82
|
private: number;
|
|
83
83
|
public: number;
|
|
84
84
|
}[]>;
|
|
85
|
+
/** Read hourly memory creation totals visible to the authenticated User in UTC. */
|
|
86
|
+
export declare function getMemoryTimelineHours(db: MemoryDb, userId: string, hours?: number): Promise<{
|
|
87
|
+
date: string;
|
|
88
|
+
private: number;
|
|
89
|
+
public: number;
|
|
90
|
+
}[]>;
|
|
85
91
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.192.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@sinclair/typebox": "^0.34.49",
|
|
27
27
|
"commander": "^14.0.3",
|
|
28
28
|
"drizzle-orm": "^0.45.2",
|
|
29
|
-
"zod": "^4.4
|
|
30
|
-
"@sentry/junior-plugin-api": "0.
|
|
29
|
+
"zod": "^4.5.4",
|
|
30
|
+
"@sentry/junior-plugin-api": "0.192.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@oxlint/plugins": "1.79.0",
|
package/src/api.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getMemory,
|
|
17
17
|
getMemoryStats,
|
|
18
18
|
getMemoryTimeline,
|
|
19
|
+
getMemoryTimelineHours,
|
|
19
20
|
InvalidMemoryCursorError,
|
|
20
21
|
listMemories,
|
|
21
22
|
MemoryNotFoundError,
|
|
@@ -44,9 +45,11 @@ export const memoryListResponseSchema = z
|
|
|
44
45
|
})
|
|
45
46
|
.strict();
|
|
46
47
|
|
|
48
|
+
const memoryBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
|
|
49
|
+
|
|
47
50
|
const memoryDashboardDaySchema = z
|
|
48
51
|
.object({
|
|
49
|
-
date:
|
|
52
|
+
date: memoryBucketSchema,
|
|
50
53
|
personal: z.number().int().min(0),
|
|
51
54
|
public: z.number().int().min(0),
|
|
52
55
|
})
|
|
@@ -55,7 +58,7 @@ const memoryDashboardDaySchema = z
|
|
|
55
58
|
const memoryCostDaySchema = z
|
|
56
59
|
.object({
|
|
57
60
|
costUsd: z.number().finite().nonnegative(),
|
|
58
|
-
date:
|
|
61
|
+
date: memoryBucketSchema,
|
|
59
62
|
events: z.number().int().min(0),
|
|
60
63
|
})
|
|
61
64
|
.strict();
|
|
@@ -64,8 +67,11 @@ export const memoryDashboardResponseSchema = z
|
|
|
64
67
|
.object({
|
|
65
68
|
days: z.array(memoryDashboardDaySchema).length(90),
|
|
66
69
|
extractionDays: z.array(memoryCostDaySchema).length(90),
|
|
70
|
+
extractionHours: z.array(memoryCostDaySchema).length(24).optional(),
|
|
67
71
|
generatedAt: z.iso.datetime(),
|
|
72
|
+
hours: z.array(memoryDashboardDaySchema).length(24).optional(),
|
|
68
73
|
recallDays: z.array(memoryCostDaySchema).length(90),
|
|
74
|
+
recallHours: z.array(memoryCostDaySchema).length(24).optional(),
|
|
69
75
|
stats: z
|
|
70
76
|
.object({
|
|
71
77
|
active: z.number().int().min(0),
|
|
@@ -163,17 +169,32 @@ export function createMemoryApi(options: MemoryApiOptions): PluginRouteApp {
|
|
|
163
169
|
|
|
164
170
|
try {
|
|
165
171
|
if (isDashboard && isRead) {
|
|
166
|
-
const [
|
|
172
|
+
const [
|
|
173
|
+
stats,
|
|
174
|
+
days,
|
|
175
|
+
hours,
|
|
176
|
+
extractionDays,
|
|
177
|
+
extractionHours,
|
|
178
|
+
recallDays,
|
|
179
|
+
recallHours,
|
|
180
|
+
] = await Promise.all([
|
|
167
181
|
getMemoryStats(options.db, userId),
|
|
168
182
|
getMemoryTimeline(options.db, userId, 90),
|
|
183
|
+
getMemoryTimelineHours(options.db, userId, 24),
|
|
169
184
|
options.eventStats.costsByDay({
|
|
170
185
|
days: 90,
|
|
171
186
|
eventName: "memories_captured",
|
|
172
187
|
}),
|
|
188
|
+
options.eventStats.costsByHour({
|
|
189
|
+
eventName: "memories_captured",
|
|
190
|
+
}),
|
|
173
191
|
options.eventStats.costsByDay({
|
|
174
192
|
days: 90,
|
|
175
193
|
eventName: "memories_recalled",
|
|
176
194
|
}),
|
|
195
|
+
options.eventStats.costsByHour({
|
|
196
|
+
eventName: "memories_recalled",
|
|
197
|
+
}),
|
|
177
198
|
]);
|
|
178
199
|
const { private: personal, ...dashboardStats } = stats;
|
|
179
200
|
const body = memoryDashboardResponseSchema.parse({
|
|
@@ -182,8 +203,14 @@ export function createMemoryApi(options: MemoryApiOptions): PluginRouteApp {
|
|
|
182
203
|
personal,
|
|
183
204
|
})),
|
|
184
205
|
extractionDays,
|
|
206
|
+
extractionHours,
|
|
185
207
|
generatedAt: new Date().toISOString(),
|
|
208
|
+
hours: hours.map(({ private: personal, ...day }) => ({
|
|
209
|
+
...day,
|
|
210
|
+
personal,
|
|
211
|
+
})),
|
|
186
212
|
recallDays,
|
|
213
|
+
recallHours,
|
|
187
214
|
stats: { ...dashboardStats, personal },
|
|
188
215
|
});
|
|
189
216
|
return request.method === "HEAD"
|
|
@@ -8,6 +8,7 @@ import { juniorMemoryEmbeddings, juniorMemoryMemories } from "./db/schema";
|
|
|
8
8
|
import type { MemoryDb } from "./store";
|
|
9
9
|
|
|
10
10
|
const DAY_MS = 24 * 60 * 60 * 1_000;
|
|
11
|
+
// TODO: add hour categories + `1` when these system widgets can plot 24h hourly.
|
|
11
12
|
const WINDOWS = [7, 30, 90] as const;
|
|
12
13
|
|
|
13
14
|
const memoryDaySchema = z
|
|
@@ -212,7 +213,7 @@ export async function buildMemoryOperationalReport(args: {
|
|
|
212
213
|
public: day.public,
|
|
213
214
|
},
|
|
214
215
|
})),
|
|
215
|
-
description: "Memories stored
|
|
216
|
+
description: "Memories stored by scope",
|
|
216
217
|
id: "memories-created",
|
|
217
218
|
series: [
|
|
218
219
|
{ key: "private", label: "Private" },
|
package/src/viewer.ts
CHANGED
|
@@ -391,3 +391,51 @@ export async function getMemoryTimeline(
|
|
|
391
391
|
};
|
|
392
392
|
});
|
|
393
393
|
}
|
|
394
|
+
|
|
395
|
+
/** Read hourly memory creation totals visible to the authenticated User in UTC. */
|
|
396
|
+
export async function getMemoryTimelineHours(
|
|
397
|
+
db: MemoryDb,
|
|
398
|
+
userId: string,
|
|
399
|
+
hours = 24,
|
|
400
|
+
) {
|
|
401
|
+
const end = new Date();
|
|
402
|
+
end.setUTCMinutes(0, 0, 0);
|
|
403
|
+
const startMs = end.getTime() - (hours - 1) * 60 * 60 * 1_000;
|
|
404
|
+
const rows = await db
|
|
405
|
+
.select({
|
|
406
|
+
date: sql<string>`to_char(to_timestamp(${juniorMemoryMemories.createdAtMs} / 1000.0) AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24')`.as(
|
|
407
|
+
"date",
|
|
408
|
+
),
|
|
409
|
+
private:
|
|
410
|
+
sql<number>`count(*) filter (where ${juniorMemoryMemories.scope} = 'private')`.mapWith(
|
|
411
|
+
Number,
|
|
412
|
+
),
|
|
413
|
+
public:
|
|
414
|
+
sql<number>`count(*) filter (where ${juniorMemoryMemories.scope} = 'public')`.mapWith(
|
|
415
|
+
Number,
|
|
416
|
+
),
|
|
417
|
+
})
|
|
418
|
+
.from(juniorMemoryMemories)
|
|
419
|
+
.where(
|
|
420
|
+
and(
|
|
421
|
+
visibleScopePredicate(userId),
|
|
422
|
+
gt(juniorMemoryMemories.createdAtMs, startMs - 1),
|
|
423
|
+
),
|
|
424
|
+
)
|
|
425
|
+
.groupBy(
|
|
426
|
+
sql`to_char(to_timestamp(${juniorMemoryMemories.createdAtMs} / 1000.0) AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24')`,
|
|
427
|
+
);
|
|
428
|
+
const byHour = new Map(rows.map((row) => [row.date, row]));
|
|
429
|
+
return Array.from({ length: hours }, (_, index) => {
|
|
430
|
+
const date = new Date(startMs + index * 60 * 60 * 1_000)
|
|
431
|
+
.toISOString()
|
|
432
|
+
.slice(0, 13);
|
|
433
|
+
const row = byHour.get(date);
|
|
434
|
+
return {
|
|
435
|
+
date,
|
|
436
|
+
private: row?.private ?? 0,
|
|
437
|
+
public: row?.public ?? 0,
|
|
438
|
+
};
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|