@fatagnus/convex-feedback 0.2.3 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fatagnus/convex-feedback",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Bug reports and feedback collection component for Convex applications with AI analysis and email notifications",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -19,32 +19,23 @@ import { components, internal } from "../_generated/api";
19
19
  import { internalAction, internalQuery } from "../_generated/server";
20
20
  import type { BugSeverity, Effort } from "../schema";
21
21
 
22
- // Create OpenRouter provider
23
- const openrouter = createOpenAICompatible({
24
- name: "openrouter",
25
- baseURL: "https://openrouter.ai/api/v1",
26
- headers: {
27
- Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
28
- },
29
- });
22
+ // Helper to create OpenRouter provider dynamically
23
+ // This is created dynamically because Convex components don't inherit parent env vars
24
+ function createOpenRouterProvider(apiKey: string) {
25
+ return createOpenAICompatible({
26
+ name: "openrouter",
27
+ baseURL: "https://openrouter.ai/api/v1",
28
+ headers: {
29
+ Authorization: `Bearer ${apiKey}`,
30
+ },
31
+ });
32
+ }
30
33
 
31
34
  // Agent name constant
32
35
  const AGENT_NAME = "Bug Report Analyst";
33
36
 
34
- // ============================================================================
35
- // Agent Definition
36
- // ============================================================================
37
-
38
- /**
39
- * Bug Report Analysis Agent
40
- *
41
- * Analyzes bug report submissions and generates comprehensive analysis.
42
- */
43
- export const bugReportAgent = new Agent(components.agent, {
44
- name: AGENT_NAME,
45
- languageModel: openrouter.languageModel("anthropic/claude-sonnet-4"),
46
-
47
- instructions: `You are the Bug Report Analyst, an AI assistant that analyzes bug report submissions.
37
+ // Agent instructions (shared between dynamic agent instances)
38
+ const BUG_REPORT_AGENT_INSTRUCTIONS = `You are the Bug Report Analyst, an AI assistant that analyzes bug report submissions.
48
39
 
49
40
  When given a bug report, you will:
50
41
  1. **Summarize** the bug in 2-3 clear sentences
@@ -74,11 +65,7 @@ Always respond in the following JSON format:
74
65
  - Reproduction steps should be specific and actionable
75
66
  - Suggested fix should be practical and implementable
76
67
  - Effort estimation should account for investigation, fix, testing, and deployment
77
- - Severity should reflect user impact and business criticality`,
78
-
79
- tools: {},
80
- maxSteps: 3,
81
- });
68
+ - Severity should reflect user impact and business criticality`;
82
69
 
83
70
  // ============================================================================
84
71
  // Internal Queries
@@ -142,7 +129,8 @@ export const processBugReport = internalAction({
142
129
  }),
143
130
  handler: async (ctx, args): Promise<{ success: boolean; error?: string }> => {
144
131
  // Check if OpenRouter API key is configured
145
- if (!process.env.OPENROUTER_API_KEY) {
132
+ const apiKey = process.env.OPENROUTER_API_KEY;
133
+ if (!apiKey) {
146
134
  console.log("OPENROUTER_API_KEY not configured, skipping AI analysis");
147
135
  // Still try to send notifications without AI analysis
148
136
  try {
@@ -170,6 +158,18 @@ export const processBugReport = internalAction({
170
158
  title: `Bug Report Analysis: ${bugReport.title}`,
171
159
  });
172
160
 
161
+ // Create OpenRouter provider dynamically with the API key
162
+ const openrouter = createOpenRouterProvider(apiKey);
163
+
164
+ // Create agent dynamically to ensure API key is available at runtime
165
+ const bugReportAgent = new Agent(components.agent, {
166
+ name: AGENT_NAME,
167
+ languageModel: openrouter.languageModel("anthropic/claude-sonnet-4"),
168
+ instructions: BUG_REPORT_AGENT_INSTRUCTIONS,
169
+ tools: {},
170
+ maxSteps: 3,
171
+ });
172
+
173
173
  // Build the prompt for analysis
174
174
  const consoleErrorsSection = bugReport.consoleErrors
175
175
  ? `**Console Errors:** ${bugReport.consoleErrors}`
@@ -18,32 +18,23 @@ import { components, internal } from "../_generated/api";
18
18
  import { internalAction, internalQuery } from "../_generated/server";
19
19
  import type { FeedbackPriority, Effort } from "../schema";
20
20
 
21
- // Create OpenRouter provider
22
- const openrouter = createOpenAICompatible({
23
- name: "openrouter",
24
- baseURL: "https://openrouter.ai/api/v1",
25
- headers: {
26
- Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
27
- },
28
- });
21
+ // Helper to create OpenRouter provider dynamically
22
+ // This is created dynamically because Convex components don't inherit parent env vars
23
+ function createOpenRouterProvider(apiKey: string) {
24
+ return createOpenAICompatible({
25
+ name: "openrouter",
26
+ baseURL: "https://openrouter.ai/api/v1",
27
+ headers: {
28
+ Authorization: `Bearer ${apiKey}`,
29
+ },
30
+ });
31
+ }
29
32
 
30
33
  // Agent name constant
31
34
  const AGENT_NAME = "Feedback Analyst";
32
35
 
33
- // ============================================================================
34
- // Agent Definition
35
- // ============================================================================
36
-
37
- /**
38
- * Feedback Analysis Agent
39
- *
40
- * Analyzes feedback submissions and generates comprehensive reports.
41
- */
42
- export const feedbackAgent = new Agent(components.agent, {
43
- name: AGENT_NAME,
44
- languageModel: openrouter.languageModel("anthropic/claude-sonnet-4"),
45
-
46
- instructions: `You are the Feedback Analyst, an AI assistant that analyzes user feedback submissions.
36
+ // Agent instructions (shared between dynamic agent instances)
37
+ const FEEDBACK_AGENT_INSTRUCTIONS = `You are the Feedback Analyst, an AI assistant that analyzes user feedback submissions.
47
38
 
48
39
  When given feedback, you will:
49
40
  1. **Summarize** the feedback in 2-3 clear sentences
@@ -70,11 +61,7 @@ Always respond in the following JSON format:
70
61
  - Consider both technical and business impact
71
62
  - Action items should be specific and actionable
72
63
  - Effort estimation should account for development, testing, and deployment
73
- - Priority should reflect urgency and user impact`,
74
-
75
- tools: {},
76
- maxSteps: 3,
77
- });
64
+ - Priority should reflect urgency and user impact`;
78
65
 
79
66
  // ============================================================================
80
67
  // Internal Queries
@@ -138,7 +125,8 @@ export const processFeedback = internalAction({
138
125
  }),
139
126
  handler: async (ctx, args): Promise<{ success: boolean; error?: string }> => {
140
127
  // Check if OpenRouter API key is configured
141
- if (!process.env.OPENROUTER_API_KEY) {
128
+ const apiKey = process.env.OPENROUTER_API_KEY;
129
+ if (!apiKey) {
142
130
  console.log("OPENROUTER_API_KEY not configured, skipping AI analysis");
143
131
  // Still try to send notifications without AI analysis
144
132
  try {
@@ -166,6 +154,18 @@ export const processFeedback = internalAction({
166
154
  title: `Feedback Analysis: ${feedback.title}`,
167
155
  });
168
156
 
157
+ // Create OpenRouter provider dynamically with the API key
158
+ const openrouter = createOpenRouterProvider(apiKey);
159
+
160
+ // Create agent dynamically to ensure API key is available at runtime
161
+ const feedbackAgent = new Agent(components.agent, {
162
+ name: AGENT_NAME,
163
+ languageModel: openrouter.languageModel("anthropic/claude-sonnet-4"),
164
+ instructions: FEEDBACK_AGENT_INSTRUCTIONS,
165
+ tools: {},
166
+ maxSteps: 3,
167
+ });
168
+
169
169
  // Build the prompt for analysis
170
170
  const analysisPrompt = `Please analyze the following feedback submission:
171
171