couchloop-eq-mcp 2.0.3 → 2.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/clients/shrinkChatClient.d.ts +28 -28
- package/dist/db/client.d.ts +11 -19
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +30 -62
- package/dist/db/client.js.map +1 -1
- package/dist/resources/journey-status.d.ts.map +1 -1
- package/dist/resources/journey-status.js +10 -12
- package/dist/resources/journey-status.js.map +1 -1
- package/dist/resources/session-summary.d.ts.map +1 -1
- package/dist/resources/session-summary.js +33 -33
- package/dist/resources/session-summary.js.map +1 -1
- package/dist/resources/user-context.d.ts.map +1 -1
- package/dist/resources/user-context.js +26 -41
- package/dist/resources/user-context.js.map +1 -1
- package/dist/tools/checkpoint.d.ts +1 -8
- package/dist/tools/checkpoint.d.ts.map +1 -1
- package/dist/tools/checkpoint.js +47 -49
- package/dist/tools/checkpoint.js.map +1 -1
- package/dist/tools/generate-upgrade-report.d.ts +2 -2
- package/dist/tools/guard.d.ts +3 -3
- package/dist/tools/index.d.ts +2 -4
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/insight.d.ts +10 -49
- package/dist/tools/insight.d.ts.map +1 -1
- package/dist/tools/insight.js +78 -91
- package/dist/tools/insight.js.map +1 -1
- package/dist/tools/journey.d.ts +5 -5
- package/dist/tools/journey.d.ts.map +1 -1
- package/dist/tools/journey.js +47 -39
- package/dist/tools/journey.js.map +1 -1
- package/dist/tools/pre-review-code.d.ts +2 -2
- package/dist/tools/prevent-ai-errors.d.ts +1 -1
- package/dist/tools/primary-tools.d.ts +8 -0
- package/dist/tools/primary-tools.d.ts.map +1 -1
- package/dist/tools/primary-tools.js +51 -20
- package/dist/tools/primary-tools.js.map +1 -1
- package/dist/tools/protect-files.d.ts +1 -1
- package/dist/tools/sendMessage.d.ts.map +1 -1
- package/dist/tools/sendMessage.js +52 -38
- package/dist/tools/sendMessage.js.map +1 -1
- package/dist/tools/session-manager.d.ts.map +1 -1
- package/dist/tools/session-manager.js +88 -70
- package/dist/tools/session-manager.js.map +1 -1
- package/dist/tools/session.d.ts +7 -86
- package/dist/tools/session.d.ts.map +1 -1
- package/dist/tools/session.js +68 -72
- package/dist/tools/session.js.map +1 -1
- package/dist/tools/smart-context.d.ts +1 -1
- package/dist/tools/status.d.ts +9 -2
- package/dist/tools/status.d.ts.map +1 -1
- package/dist/tools/status.js +112 -63
- package/dist/tools/status.js.map +1 -1
- package/dist/tools/verify.d.ts +2 -2
- package/dist/tools/verify.js.map +1 -1
- package/dist/types/auth.d.ts +2 -2
- package/dist/types/checkpoint.d.ts +4 -4
- package/dist/types/file-protection.d.ts +2 -2
- package/dist/types/insight.d.ts +10 -10
- package/dist/types/journey.d.ts +40 -12
- package/dist/types/journey.d.ts.map +1 -1
- package/dist/types/journey.js +2 -0
- package/dist/types/journey.js.map +1 -1
- package/dist/types/session.d.ts +8 -8
- package/dist/workflows/engine.d.ts +2 -2
- package/dist/workflows/engine.d.ts.map +1 -1
- package/dist/workflows/engine.js +81 -82
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/index.d.ts +4 -4
- package/package.json +2 -10
package/dist/tools/checkpoint.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { sessions, journeys, checkpoints, insights, governanceAuditLog } from '../db/schema.js';
|
|
3
|
-
import { eq } from 'drizzle-orm';
|
|
1
|
+
import { getSupabaseClient, throwOnError } from '../db/supabase-helpers.js';
|
|
4
2
|
import { SaveCheckpointSchema } from '../types/checkpoint.js';
|
|
5
3
|
import { handleError } from '../utils/errors.js';
|
|
6
4
|
import { logger } from '../utils/logger.js';
|
|
@@ -10,7 +8,7 @@ import { governancePostCheck } from '../governance/middleware.js';
|
|
|
10
8
|
export async function saveCheckpoint(args) {
|
|
11
9
|
try {
|
|
12
10
|
const input = SaveCheckpointSchema.parse(args);
|
|
13
|
-
const
|
|
11
|
+
const supabase = getSupabaseClient();
|
|
14
12
|
// Get or create session implicitly if not provided
|
|
15
13
|
// FIX 1: Session object returned directly — no redundant re-fetch
|
|
16
14
|
const { sessionId, session, isNew } = await getOrCreateSession(input.session_id, input.auth, 'Checkpoint session');
|
|
@@ -21,57 +19,57 @@ export async function saveCheckpoint(args) {
|
|
|
21
19
|
let stepId = 'freeform';
|
|
22
20
|
let nextStep = null;
|
|
23
21
|
let journeyComplete = false;
|
|
24
|
-
if (session.
|
|
25
|
-
const
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
22
|
+
if (session.journey_id) {
|
|
23
|
+
const journey = throwOnError(await supabase
|
|
24
|
+
.from('journeys')
|
|
25
|
+
.select('*')
|
|
26
|
+
.eq('id', session.journey_id)
|
|
27
|
+
.maybeSingle());
|
|
30
28
|
if (journey && journey.steps) {
|
|
31
|
-
const currentStepData = journey.steps[session.
|
|
29
|
+
const currentStepData = journey.steps[session.current_step];
|
|
32
30
|
if (currentStepData) {
|
|
33
31
|
stepId = currentStepData.id;
|
|
34
32
|
}
|
|
35
33
|
// Advance to next step if requested
|
|
36
34
|
if (input.advance_step) {
|
|
37
|
-
const nextStepIndex = session.
|
|
35
|
+
const nextStepIndex = session.current_step + 1;
|
|
38
36
|
if (nextStepIndex < journey.steps.length) {
|
|
39
37
|
nextStep = journey.steps[nextStepIndex];
|
|
40
38
|
// Update session's current step
|
|
41
|
-
await
|
|
42
|
-
.
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
throwOnError(await supabase
|
|
40
|
+
.from('sessions')
|
|
41
|
+
.update({
|
|
42
|
+
current_step: nextStepIndex,
|
|
43
|
+
last_active_at: new Date().toISOString(),
|
|
46
44
|
})
|
|
47
|
-
.
|
|
45
|
+
.eq('id', session.id));
|
|
48
46
|
}
|
|
49
47
|
else {
|
|
50
48
|
// Journey complete
|
|
51
49
|
journeyComplete = true;
|
|
52
|
-
await
|
|
53
|
-
.
|
|
54
|
-
.
|
|
50
|
+
throwOnError(await supabase
|
|
51
|
+
.from('sessions')
|
|
52
|
+
.update({
|
|
55
53
|
status: 'completed',
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
completed_at: new Date().toISOString(),
|
|
55
|
+
last_active_at: new Date().toISOString(),
|
|
58
56
|
})
|
|
59
|
-
.
|
|
57
|
+
.eq('id', session.id));
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
// Save checkpoint
|
|
65
|
-
const checkpointResult = await
|
|
66
|
-
.
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const checkpointResult = throwOnError(await supabase
|
|
64
|
+
.from('checkpoints')
|
|
65
|
+
.insert({
|
|
66
|
+
session_id: sessionId,
|
|
67
|
+
step_id: stepId,
|
|
70
68
|
key: input.key,
|
|
71
69
|
value: input.value,
|
|
72
70
|
})
|
|
73
|
-
.
|
|
74
|
-
const checkpoint = checkpointResult[0];
|
|
71
|
+
.select());
|
|
72
|
+
const checkpoint = (checkpointResult ?? [])[0];
|
|
75
73
|
logger.info(`Saved checkpoint: ${checkpoint.id} for session: ${session.id}`);
|
|
76
74
|
// Extended response
|
|
77
75
|
const response = {
|
|
@@ -98,17 +96,17 @@ export async function saveCheckpoint(args) {
|
|
|
98
96
|
// Log to governance audit
|
|
99
97
|
if (govResult.issues.length > 0) {
|
|
100
98
|
try {
|
|
101
|
-
await
|
|
102
|
-
|
|
99
|
+
throwOnError(await supabase.from('governance_audit_log').insert({
|
|
100
|
+
action_type: 'checkpoint_review',
|
|
103
101
|
reason: govResult.issues.join('; '),
|
|
104
|
-
|
|
102
|
+
confidence_score: Math.round(govResult.confidence * 100),
|
|
105
103
|
metadata: {
|
|
106
104
|
checkpoint_id: checkpoint.id,
|
|
107
105
|
session_id: sessionId,
|
|
108
106
|
key: input.key,
|
|
109
107
|
issues: govResult.issues,
|
|
110
108
|
},
|
|
111
|
-
});
|
|
109
|
+
}));
|
|
112
110
|
}
|
|
113
111
|
catch (auditError) {
|
|
114
112
|
logger.warn('Failed to log governance audit:', auditError);
|
|
@@ -120,14 +118,14 @@ export async function saveCheckpoint(args) {
|
|
|
120
118
|
try {
|
|
121
119
|
// We already have the session with userId, no need to extract user again
|
|
122
120
|
const contentStr = typeof input.value === 'string' ? input.value : JSON.stringify(input.value);
|
|
123
|
-
const insightResult = await
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
const insightResult = throwOnError(await supabase.from('insights').insert({
|
|
122
|
+
user_id: session.user_id,
|
|
123
|
+
session_id: sessionId,
|
|
126
124
|
content: `[${input.key}] ${contentStr}`,
|
|
127
125
|
tags: input.insight_tags || [input.key],
|
|
128
|
-
}).
|
|
129
|
-
if (insightResult[0]) {
|
|
130
|
-
response.insight_id = insightResult[0].id;
|
|
126
|
+
}).select());
|
|
127
|
+
if ((insightResult ?? [])[0]) {
|
|
128
|
+
response.insight_id = (insightResult ?? [])[0].id;
|
|
131
129
|
logger.info(`Also saved as insight: ${response.insight_id}`);
|
|
132
130
|
}
|
|
133
131
|
}
|
|
@@ -158,21 +156,21 @@ export async function saveCheckpoint(args) {
|
|
|
158
156
|
export async function getCheckpoints(args) {
|
|
159
157
|
try {
|
|
160
158
|
const { session_id, auth } = args;
|
|
161
|
-
const
|
|
159
|
+
const supabase = getSupabaseClient();
|
|
162
160
|
// Get or create session implicitly if not provided
|
|
163
161
|
// FIX 1: Session object returned directly — no redundant re-fetch
|
|
164
162
|
const { sessionId, isNew } = await getOrCreateSession(session_id, auth);
|
|
165
163
|
// Get all checkpoints
|
|
166
|
-
const sessionCheckpoints = await
|
|
167
|
-
.
|
|
168
|
-
.
|
|
169
|
-
.
|
|
170
|
-
.
|
|
164
|
+
const sessionCheckpoints = throwOnError(await supabase
|
|
165
|
+
.from('checkpoints')
|
|
166
|
+
.select('*')
|
|
167
|
+
.eq('session_id', sessionId)
|
|
168
|
+
.order('created_at', { ascending: true }));
|
|
171
169
|
return {
|
|
172
170
|
session_id: sessionId,
|
|
173
171
|
session_created: isNew,
|
|
174
|
-
checkpoints: sessionCheckpoints,
|
|
175
|
-
count: sessionCheckpoints.length,
|
|
172
|
+
checkpoints: sessionCheckpoints ?? [],
|
|
173
|
+
count: (sessionCheckpoints ?? []).length,
|
|
176
174
|
};
|
|
177
175
|
}
|
|
178
176
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../src/tools/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../src/tools/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAsB,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAa;IAChD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAC;QAErC,mDAAmD;QACnD,kEAAkE;QAClE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,kBAAkB,CAC5D,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,IAAI,EACV,oBAAoB,CACrB,CAAC;QAEF,IAAI,OAAO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kB,IAAI,EAAE,CAAC,CAAC,MAAM;SACzC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QAClD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -58,7 +58,7 @@ export declare function handleGenerateUpgradeReport(args: unknown): Promise<{
|
|
|
58
58
|
package: string;
|
|
59
59
|
from_version: string | undefined;
|
|
60
60
|
to_version: string;
|
|
61
|
-
complexity: "
|
|
61
|
+
complexity: "low" | "medium" | "high";
|
|
62
62
|
estimated_time: string;
|
|
63
63
|
upgrade_command: string;
|
|
64
64
|
install_command: string;
|
|
@@ -75,7 +75,7 @@ export declare function handleGenerateUpgradeReport(args: unknown): Promise<{
|
|
|
75
75
|
testing_strategy: string[];
|
|
76
76
|
rollback_strategy: string;
|
|
77
77
|
risks: {
|
|
78
|
-
level: "
|
|
78
|
+
level: "low" | "medium" | "high" | "critical";
|
|
79
79
|
factors: string[];
|
|
80
80
|
mitigations: string[];
|
|
81
81
|
};
|
package/dist/tools/guard.d.ts
CHANGED
|
@@ -42,22 +42,22 @@ declare const GuardInputSchema: z.ZodObject<{
|
|
|
42
42
|
session_id: z.ZodOptional<z.ZodString>;
|
|
43
43
|
mode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["enforce", "shadow", "bypass"]>>>;
|
|
44
44
|
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
mode: "enforce" | "shadow" | "bypass";
|
|
46
|
-
response: string;
|
|
47
45
|
conversation: {
|
|
48
46
|
content: string;
|
|
49
47
|
role: "user" | "assistant";
|
|
50
48
|
}[];
|
|
49
|
+
mode: "enforce" | "shadow" | "bypass";
|
|
50
|
+
response: string;
|
|
51
51
|
domain: "clinical" | "auto" | "dev";
|
|
52
52
|
session_id?: string | undefined;
|
|
53
53
|
}, {
|
|
54
54
|
response: string;
|
|
55
|
-
mode?: "enforce" | "shadow" | "bypass" | undefined;
|
|
56
55
|
session_id?: string | undefined;
|
|
57
56
|
conversation?: {
|
|
58
57
|
content: string;
|
|
59
58
|
role: "user" | "assistant";
|
|
60
59
|
}[] | undefined;
|
|
60
|
+
mode?: "enforce" | "shadow" | "bypass" | undefined;
|
|
61
61
|
domain?: "clinical" | "auto" | "dev" | undefined;
|
|
62
62
|
}>;
|
|
63
63
|
export type GuardInput = z.infer<typeof GuardInputSchema>;
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* MCP Tools - Main Export
|
|
3
3
|
*
|
|
4
4
|
* This module provides two modes:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Set MCP_TOOL_MODE=full in environment for full mode
|
|
5
|
+
* 4 primary tools: memory, conversation, review, status
|
|
6
|
+
* Consolidated from 10 → 4 in v2.1.0
|
|
9
7
|
*/
|
|
10
8
|
export { setupTools } from "./primary-tools.js";
|
|
11
9
|
export { handleCheckVersions } from "./check-versions.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACH,eAAe,EAAE,eAAe,EAAE,YAAY,EACjD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/tools/index.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* MCP Tools - Main Export
|
|
3
3
|
*
|
|
4
4
|
* This module provides two modes:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Set MCP_TOOL_MODE=full in environment for full mode
|
|
5
|
+
* 4 primary tools: memory, conversation, review, status
|
|
6
|
+
* Consolidated from 10 → 4 in v2.1.0
|
|
9
7
|
*/
|
|
10
8
|
// Re-export the primary tools setup as default
|
|
11
9
|
export { setupTools } from "./primary-tools.js";
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+CAA+C;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,8CAA8C;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACH,eAAe,EAAE,eAAe,EAAE,YAAY,EACjD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/tools/insight.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { Insight } from '../db/schema.js';
|
|
1
2
|
import { type SaveInsightInput, type GetUserContextInput } from '../types/insight.js';
|
|
2
3
|
export interface RecentSession {
|
|
3
4
|
id: string;
|
|
4
5
|
status: string;
|
|
5
|
-
started_at:
|
|
6
|
-
completed_at:
|
|
6
|
+
started_at: string;
|
|
7
|
+
completed_at: string | null;
|
|
7
8
|
journey_id: string | null;
|
|
8
9
|
}
|
|
9
10
|
export declare function saveInsight(args: SaveInsightInput): Promise<{
|
|
@@ -21,65 +22,25 @@ export declare function getInsights(args: {
|
|
|
21
22
|
error: string;
|
|
22
23
|
details?: Record<string, unknown>;
|
|
23
24
|
} | {
|
|
24
|
-
insights:
|
|
25
|
-
id: string;
|
|
26
|
-
createdAt: Date;
|
|
27
|
-
tags: string[];
|
|
28
|
-
userId: string;
|
|
29
|
-
sessionId: string | null;
|
|
30
|
-
content: string;
|
|
31
|
-
}[];
|
|
25
|
+
insights: any[];
|
|
32
26
|
count: number;
|
|
33
27
|
}>;
|
|
34
28
|
export declare function getUserContext(args: GetUserContextInput): Promise<{
|
|
35
29
|
error: string;
|
|
36
30
|
details?: Record<string, unknown>;
|
|
37
31
|
} | {
|
|
38
|
-
user:
|
|
39
|
-
id: string;
|
|
40
|
-
externalId: string;
|
|
41
|
-
isTestAccount: boolean;
|
|
42
|
-
createdAt: Date;
|
|
43
|
-
updatedAt: Date;
|
|
44
|
-
preferences: {
|
|
45
|
-
timezone?: string;
|
|
46
|
-
preferredJourneyLength?: "short" | "medium" | "long";
|
|
47
|
-
} | null;
|
|
48
|
-
} | undefined;
|
|
32
|
+
user: any;
|
|
49
33
|
recent_insights: never[];
|
|
50
34
|
recent_sessions: never[];
|
|
51
35
|
active_session: null;
|
|
52
36
|
} | {
|
|
53
37
|
user: {
|
|
54
|
-
id:
|
|
55
|
-
preferences:
|
|
56
|
-
|
|
57
|
-
preferredJourneyLength?: "short" | "medium" | "long";
|
|
58
|
-
} | null;
|
|
59
|
-
created_at: Date;
|
|
38
|
+
id: any;
|
|
39
|
+
preferences: any;
|
|
40
|
+
created_at: any;
|
|
60
41
|
};
|
|
61
|
-
recent_insights:
|
|
62
|
-
id: string;
|
|
63
|
-
createdAt: Date;
|
|
64
|
-
tags: string[];
|
|
65
|
-
userId: string;
|
|
66
|
-
sessionId: string | null;
|
|
67
|
-
content: string;
|
|
68
|
-
}[];
|
|
42
|
+
recent_insights: Insight[];
|
|
69
43
|
recent_sessions: RecentSession[];
|
|
70
|
-
active_session:
|
|
71
|
-
id: string;
|
|
72
|
-
updatedAt: Date;
|
|
73
|
-
userId: string;
|
|
74
|
-
journeyId: string | null;
|
|
75
|
-
status: "active" | "paused" | "completed" | "abandoned";
|
|
76
|
-
currentStep: number;
|
|
77
|
-
startedAt: Date;
|
|
78
|
-
lastActiveAt: Date;
|
|
79
|
-
completedAt: Date | null;
|
|
80
|
-
metadata: unknown;
|
|
81
|
-
threadId: string | null;
|
|
82
|
-
lastSyncedAt: Date | null;
|
|
83
|
-
} | undefined;
|
|
44
|
+
active_session: any;
|
|
84
45
|
}>;
|
|
85
46
|
//# sourceMappingURL=insight.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insight.d.ts","sourceRoot":"","sources":["../../src/tools/insight.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"insight.d.ts","sourceRoot":"","sources":["../../src/tools/insight.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAA2C,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAM/H,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,gBAAgB;;;;;;GA+DvD;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE;;;;;;GA0D9G;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,mBAAmB;;;;;;;;;;;;;;;;;GAwF7D"}
|
package/dist/tools/insight.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { insights, users, sessions } from '../db/schema.js';
|
|
3
|
-
import { eq, desc, and } from 'drizzle-orm';
|
|
1
|
+
import { getSupabaseClient, throwOnError } from '../db/supabase-helpers.js';
|
|
4
2
|
import { SaveInsightSchema, GetUserContextSchema } from '../types/insight.js';
|
|
5
3
|
import { extractUserFromContext } from '../types/auth.js';
|
|
6
4
|
import { handleError, NotFoundError } from '../utils/errors.js';
|
|
@@ -8,43 +6,41 @@ import { logger } from '../utils/logger.js';
|
|
|
8
6
|
export async function saveInsight(args) {
|
|
9
7
|
try {
|
|
10
8
|
const input = SaveInsightSchema.parse(args);
|
|
11
|
-
const
|
|
9
|
+
const supabase = getSupabaseClient();
|
|
12
10
|
// Extract user ID from auth context or generate anonymous user
|
|
13
11
|
const externalUserId = await extractUserFromContext(input.auth);
|
|
14
|
-
const
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
|
|
12
|
+
const user = throwOnError(await supabase
|
|
13
|
+
.from('users')
|
|
14
|
+
.upsert({
|
|
15
|
+
external_id: externalUserId,
|
|
18
16
|
preferences: {},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
.returning();
|
|
25
|
-
const user = userResult[0];
|
|
17
|
+
updated_at: new Date().toISOString(),
|
|
18
|
+
}, { onConflict: 'external_id' })
|
|
19
|
+
.select()
|
|
20
|
+
.single());
|
|
26
21
|
// Verify session if provided
|
|
27
22
|
if (input.session_id) {
|
|
28
|
-
const
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
.
|
|
32
|
-
.
|
|
23
|
+
const session = throwOnError(await supabase
|
|
24
|
+
.from('sessions')
|
|
25
|
+
.select('*')
|
|
26
|
+
.eq('id', input.session_id)
|
|
27
|
+
.eq('user_id', user.id)
|
|
28
|
+
.maybeSingle());
|
|
33
29
|
if (!session) {
|
|
34
30
|
throw new NotFoundError('Session', input.session_id);
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
// Save insight
|
|
38
|
-
const
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const insight = throwOnError(await supabase
|
|
35
|
+
.from('insights')
|
|
36
|
+
.insert({
|
|
37
|
+
user_id: user.id,
|
|
38
|
+
session_id: input.session_id || null,
|
|
43
39
|
content: input.content,
|
|
44
40
|
tags: input.tags || [],
|
|
45
41
|
})
|
|
46
|
-
.
|
|
47
|
-
|
|
42
|
+
.select()
|
|
43
|
+
.single());
|
|
48
44
|
logger.info(`Saved insight: ${insight.id}`);
|
|
49
45
|
// Return sanitized response (no internal IDs)
|
|
50
46
|
return {
|
|
@@ -60,23 +56,24 @@ export async function saveInsight(args) {
|
|
|
60
56
|
export async function getInsights(args) {
|
|
61
57
|
try {
|
|
62
58
|
const { session_id, limit = 10, auth } = args;
|
|
63
|
-
const
|
|
59
|
+
const supabase = getSupabaseClient();
|
|
64
60
|
// Extract user ID from auth context or generate anonymous user
|
|
65
61
|
const externalUserId = await extractUserFromContext(auth);
|
|
66
|
-
const
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
.
|
|
62
|
+
const user = throwOnError(await supabase
|
|
63
|
+
.from('users')
|
|
64
|
+
.select('*')
|
|
65
|
+
.eq('external_id', externalUserId)
|
|
66
|
+
.maybeSingle());
|
|
71
67
|
if (!user) {
|
|
72
68
|
// Create user if doesn't exist
|
|
73
|
-
const
|
|
74
|
-
.
|
|
75
|
-
.
|
|
76
|
-
|
|
69
|
+
const newUser = throwOnError(await supabase
|
|
70
|
+
.from('users')
|
|
71
|
+
.insert({
|
|
72
|
+
external_id: externalUserId,
|
|
77
73
|
preferences: {},
|
|
78
74
|
})
|
|
79
|
-
.
|
|
75
|
+
.select()
|
|
76
|
+
.single());
|
|
80
77
|
if (!newUser) {
|
|
81
78
|
throw new NotFoundError('User');
|
|
82
79
|
}
|
|
@@ -85,26 +82,19 @@ export async function getInsights(args) {
|
|
|
85
82
|
count: 0,
|
|
86
83
|
};
|
|
87
84
|
}
|
|
88
|
-
let
|
|
85
|
+
let query = supabase
|
|
86
|
+
.from('insights')
|
|
87
|
+
.select('*')
|
|
88
|
+
.eq('user_id', user.id)
|
|
89
|
+
.order('created_at', { ascending: false })
|
|
90
|
+
.limit(limit);
|
|
89
91
|
if (session_id) {
|
|
90
|
-
|
|
91
|
-
.select()
|
|
92
|
-
.from(insights)
|
|
93
|
-
.where(and(eq(insights.userId, user.id), eq(insights.sessionId, session_id)))
|
|
94
|
-
.orderBy(desc(insights.createdAt))
|
|
95
|
-
.limit(limit);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
userInsights = await db
|
|
99
|
-
.select()
|
|
100
|
-
.from(insights)
|
|
101
|
-
.where(eq(insights.userId, user.id))
|
|
102
|
-
.orderBy(desc(insights.createdAt))
|
|
103
|
-
.limit(limit);
|
|
92
|
+
query = query.eq('session_id', session_id);
|
|
104
93
|
}
|
|
94
|
+
const userInsights = throwOnError(await query);
|
|
105
95
|
return {
|
|
106
|
-
insights: userInsights,
|
|
107
|
-
count: userInsights.length,
|
|
96
|
+
insights: userInsights ?? [],
|
|
97
|
+
count: (userInsights ?? []).length,
|
|
108
98
|
};
|
|
109
99
|
}
|
|
110
100
|
catch (error) {
|
|
@@ -115,23 +105,24 @@ export async function getInsights(args) {
|
|
|
115
105
|
export async function getUserContext(args) {
|
|
116
106
|
try {
|
|
117
107
|
const input = GetUserContextSchema.parse(args);
|
|
118
|
-
const
|
|
108
|
+
const supabase = getSupabaseClient();
|
|
119
109
|
// Extract user ID from auth context or generate anonymous user
|
|
120
110
|
const externalUserId = await extractUserFromContext(input.auth);
|
|
121
|
-
const
|
|
122
|
-
.
|
|
123
|
-
.
|
|
124
|
-
.
|
|
125
|
-
.
|
|
111
|
+
const user = throwOnError(await supabase
|
|
112
|
+
.from('users')
|
|
113
|
+
.select('*')
|
|
114
|
+
.eq('external_id', externalUserId)
|
|
115
|
+
.maybeSingle());
|
|
126
116
|
if (!user) {
|
|
127
117
|
// Create user if doesn't exist
|
|
128
|
-
const
|
|
129
|
-
.
|
|
130
|
-
.
|
|
131
|
-
|
|
118
|
+
const newUser = throwOnError(await supabase
|
|
119
|
+
.from('users')
|
|
120
|
+
.insert({
|
|
121
|
+
external_id: externalUserId,
|
|
132
122
|
preferences: {},
|
|
133
123
|
})
|
|
134
|
-
.
|
|
124
|
+
.select()
|
|
125
|
+
.single());
|
|
135
126
|
return {
|
|
136
127
|
user: newUser,
|
|
137
128
|
recent_insights: [],
|
|
@@ -142,41 +133,37 @@ export async function getUserContext(args) {
|
|
|
142
133
|
// Get recent insights if requested
|
|
143
134
|
let recentInsights = [];
|
|
144
135
|
if (input.include_recent_insights) {
|
|
145
|
-
recentInsights = await
|
|
146
|
-
.
|
|
147
|
-
.
|
|
148
|
-
.
|
|
149
|
-
.
|
|
150
|
-
.limit(5);
|
|
136
|
+
recentInsights = throwOnError(await supabase
|
|
137
|
+
.from('insights')
|
|
138
|
+
.select('*')
|
|
139
|
+
.eq('user_id', user.id)
|
|
140
|
+
.order('created_at', { ascending: false })
|
|
141
|
+
.limit(5)) ?? [];
|
|
151
142
|
}
|
|
152
143
|
// Get recent sessions if requested
|
|
153
144
|
let recentSessions = [];
|
|
154
145
|
if (input.include_session_history) {
|
|
155
|
-
recentSessions = await
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
started_at:
|
|
160
|
-
|
|
161
|
-
journey_id: sessions.journeyId,
|
|
162
|
-
})
|
|
163
|
-
.from(sessions)
|
|
164
|
-
.where(eq(sessions.userId, user.id))
|
|
165
|
-
.orderBy(desc(sessions.startedAt))
|
|
166
|
-
.limit(5);
|
|
146
|
+
recentSessions = throwOnError(await supabase
|
|
147
|
+
.from('sessions')
|
|
148
|
+
.select('id, status, started_at, completed_at, journey_id')
|
|
149
|
+
.eq('user_id', user.id)
|
|
150
|
+
.order('started_at', { ascending: false })
|
|
151
|
+
.limit(5)) ?? [];
|
|
167
152
|
}
|
|
168
153
|
// Get active session
|
|
169
|
-
const
|
|
170
|
-
.
|
|
171
|
-
.
|
|
172
|
-
.
|
|
173
|
-
.
|
|
174
|
-
.
|
|
154
|
+
const activeSession = throwOnError(await supabase
|
|
155
|
+
.from('sessions')
|
|
156
|
+
.select('*')
|
|
157
|
+
.eq('user_id', user.id)
|
|
158
|
+
.eq('status', 'active')
|
|
159
|
+
.order('last_active_at', { ascending: false })
|
|
160
|
+
.limit(1)
|
|
161
|
+
.maybeSingle());
|
|
175
162
|
return {
|
|
176
163
|
user: {
|
|
177
164
|
id: user.id,
|
|
178
165
|
preferences: user.preferences,
|
|
179
|
-
created_at: user.
|
|
166
|
+
created_at: user.created_at,
|
|
180
167
|
},
|
|
181
168
|
recent_insights: recentInsights,
|
|
182
169
|
recent_sessions: recentSessions,
|