@nordsym/apiclaw 1.8.6 → 1.8.7

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.
Files changed (125) hide show
  1. package/README.md +4 -4
  2. package/apiclaw-README.md +12 -12
  3. package/convex/_generated/api.d.ts +4 -0
  4. package/convex/apiKeys.ts +220 -0
  5. package/convex/directCall.ts +49 -14
  6. package/convex/email.ts +5 -5
  7. package/convex/http.ts +598 -40
  8. package/convex/logs.ts +26 -22
  9. package/convex/migrateProviderWorkspaces.ts +154 -35
  10. package/convex/providers.ts +313 -203
  11. package/convex/schema.ts +50 -1
  12. package/convex/searchLogs.ts +2 -6
  13. package/convex/seedPratham.ts +1 -1
  14. package/convex/spendAlerts.ts +2 -2
  15. package/convex/stripeActions.ts +1 -1
  16. package/convex/updateAPIStatus.ts +2 -3
  17. package/convex/workspaceSettings.ts +136 -0
  18. package/dist/cli/commands/demo.js +2 -2
  19. package/dist/cli/commands/doctor.js +1 -1
  20. package/dist/cli/commands/login.js +1 -1
  21. package/dist/cli/commands/setup.js +2 -2
  22. package/dist/discovery.js +1 -1
  23. package/dist/execute.js +3 -3
  24. package/dist/index.js +13 -13
  25. package/dist/ui/errors.js +16 -16
  26. package/dist/ui/prompts.js +1 -1
  27. package/email-templates/filestack-provider-outreach.html +1 -1
  28. package/email-templates/partnership-template.html +1 -1
  29. package/email-templates/pratham-partnership-draft.html +2 -2
  30. package/package.json +2 -2
  31. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  32. package/reports/session-report-2026-04-05.html +433 -0
  33. package/src/cli/commands/demo.ts +2 -2
  34. package/src/cli/commands/doctor.ts +1 -1
  35. package/src/cli/commands/login.ts +1 -1
  36. package/src/cli/commands/setup.ts +2 -2
  37. package/src/discovery.ts +1 -1
  38. package/src/execute.ts +3 -3
  39. package/src/index.ts +14 -14
  40. package/src/ui/errors.ts +16 -16
  41. package/src/ui/prompts.ts +1 -1
  42. package/convex/adminActivate.d.ts +0 -3
  43. package/convex/adminActivate.js +0 -47
  44. package/convex/adminStats.d.ts +0 -9
  45. package/convex/adminStats.js +0 -280
  46. package/convex/agents.d.ts +0 -84
  47. package/convex/agents.js +0 -809
  48. package/convex/analytics.d.ts +0 -5
  49. package/convex/analytics.js +0 -167
  50. package/convex/backfillAnalytics.d.ts +0 -2
  51. package/convex/backfillAnalytics.js +0 -20
  52. package/convex/backfillSearchLogs.d.ts +0 -2
  53. package/convex/backfillSearchLogs.js +0 -29
  54. package/convex/billing.d.ts +0 -88
  55. package/convex/billing.js +0 -655
  56. package/convex/capabilities.d.ts +0 -9
  57. package/convex/capabilities.js +0 -145
  58. package/convex/chains.d.ts +0 -68
  59. package/convex/chains.js +0 -1105
  60. package/convex/credits.d.ts +0 -25
  61. package/convex/credits.js +0 -186
  62. package/convex/crons.d.ts +0 -3
  63. package/convex/crons.js +0 -17
  64. package/convex/debugFilestackLogs.d.ts +0 -2
  65. package/convex/debugFilestackLogs.js +0 -17
  66. package/convex/debugGetToken.d.ts +0 -2
  67. package/convex/debugGetToken.js +0 -18
  68. package/convex/directCall.d.ts +0 -72
  69. package/convex/directCall.js +0 -627
  70. package/convex/earnProgress.d.ts +0 -58
  71. package/convex/earnProgress.js +0 -649
  72. package/convex/email.d.ts +0 -14
  73. package/convex/email.js +0 -300
  74. package/convex/feedback.d.ts +0 -7
  75. package/convex/feedback.js +0 -227
  76. package/convex/http.d.ts +0 -3
  77. package/convex/http.js +0 -1408
  78. package/convex/inbound.d.ts +0 -2
  79. package/convex/inbound.js +0 -32
  80. package/convex/logs.d.ts +0 -48
  81. package/convex/logs.js +0 -621
  82. package/convex/migrateFilestack.d.ts +0 -2
  83. package/convex/migrateFilestack.js +0 -74
  84. package/convex/migratePartnersProd.d.ts +0 -8
  85. package/convex/migratePartnersProd.js +0 -165
  86. package/convex/migratePratham.d.ts +0 -2
  87. package/convex/migratePratham.js +0 -121
  88. package/convex/migrateProviderWorkspaces.d.ts +0 -2
  89. package/convex/migrateProviderWorkspaces.js +0 -55
  90. package/convex/mou.d.ts +0 -6
  91. package/convex/mou.js +0 -82
  92. package/convex/providerKeys.d.ts +0 -31
  93. package/convex/providerKeys.js +0 -257
  94. package/convex/providers.d.ts +0 -35
  95. package/convex/providers.js +0 -922
  96. package/convex/purchases.d.ts +0 -7
  97. package/convex/purchases.js +0 -157
  98. package/convex/ratelimit.d.ts +0 -4
  99. package/convex/ratelimit.js +0 -91
  100. package/convex/searchLogs.d.ts +0 -13
  101. package/convex/searchLogs.js +0 -246
  102. package/convex/seedAPILayerAPIs.d.ts +0 -7
  103. package/convex/seedAPILayerAPIs.js +0 -177
  104. package/convex/seedDirectCallConfigs.d.ts +0 -2
  105. package/convex/seedDirectCallConfigs.js +0 -324
  106. package/convex/seedPratham.d.ts +0 -6
  107. package/convex/seedPratham.js +0 -150
  108. package/convex/spendAlerts.d.ts +0 -36
  109. package/convex/spendAlerts.js +0 -380
  110. package/convex/stripeActions.d.ts +0 -19
  111. package/convex/stripeActions.js +0 -411
  112. package/convex/teams.d.ts +0 -21
  113. package/convex/teams.js +0 -215
  114. package/convex/telemetry.d.ts +0 -4
  115. package/convex/telemetry.js +0 -74
  116. package/convex/updateAPIStatus.d.ts +0 -6
  117. package/convex/updateAPIStatus.js +0 -40
  118. package/convex/usage.d.ts +0 -27
  119. package/convex/usage.js +0 -229
  120. package/convex/waitlist.d.ts +0 -4
  121. package/convex/waitlist.js +0 -49
  122. package/convex/webhooks.d.ts +0 -12
  123. package/convex/webhooks.js +0 -410
  124. package/convex/workspaces.d.ts +0 -33
  125. package/convex/workspaces.js +0 -991
@@ -1,7 +0,0 @@
1
- export declare const purchaseAccess: any;
2
- export declare const getAgentPurchases: any;
3
- export declare const getActivePurchase: any;
4
- export declare const getUsage: any;
5
- export declare const recordUsage: any;
6
- export declare const getBalanceSummary: any;
7
- //# sourceMappingURL=purchases.d.ts.map
@@ -1,157 +0,0 @@
1
- import { v } from "convex/values";
2
- import { mutation, query } from "./_generated/server";
3
- // Provider pricing (credits per dollar)
4
- const CREDITS_PER_DOLLAR = {
5
- "46elks": 30, // ~30 SMS per dollar
6
- twilio: 25, // ~25 SMS per dollar
7
- resend: 1000, // ~1000 emails per dollar
8
- brave_search: 200, // ~200 searches per dollar
9
- openrouter: 100, // ~100k tokens per dollar
10
- elevenlabs: 3333, // ~3333 characters per dollar
11
- };
12
- // Calculate credits for a provider purchase
13
- function calculateCredits(providerId, amountUsd) {
14
- const rate = CREDITS_PER_DOLLAR[providerId] || 100;
15
- return Math.floor(amountUsd * rate);
16
- }
17
- // Purchase API access
18
- export const purchaseAccess = mutation({
19
- args: {
20
- agentId: v.string(),
21
- providerId: v.string(),
22
- amountUsd: v.number(),
23
- credentials: v.any(), // Credentials passed from server side
24
- },
25
- handler: async (ctx, args) => {
26
- // Check balance
27
- const credits = await ctx.db
28
- .query("agentCredits")
29
- .withIndex("by_agentId", (q) => q.eq("agentId", args.agentId))
30
- .first();
31
- if (!credits || credits.balanceUsd < args.amountUsd) {
32
- throw new Error(`Insufficient balance: have $${(credits?.balanceUsd || 0).toFixed(2)}, need $${args.amountUsd.toFixed(2)}`);
33
- }
34
- // Deduct credits
35
- await ctx.db.patch(credits._id, {
36
- balanceUsd: credits.balanceUsd - args.amountUsd,
37
- updatedAt: Date.now(),
38
- });
39
- // Calculate credits granted
40
- const creditsGranted = calculateCredits(args.providerId, args.amountUsd);
41
- // Create purchase record
42
- const purchaseId = await ctx.db.insert("purchases", {
43
- agentId: args.agentId,
44
- providerId: args.providerId,
45
- amountUsd: args.amountUsd,
46
- creditsGranted,
47
- status: "active",
48
- credentials: args.credentials,
49
- createdAt: Date.now(),
50
- });
51
- // Initialize usage tracking
52
- await ctx.db.insert("usage", {
53
- purchaseId,
54
- providerId: args.providerId,
55
- unitsUsed: 0,
56
- unitsRemaining: creditsGranted,
57
- costIncurredUsd: 0,
58
- lastUsedAt: Date.now(),
59
- });
60
- return await ctx.db.get(purchaseId);
61
- },
62
- });
63
- // Get all purchases for an agent
64
- export const getAgentPurchases = query({
65
- args: { agentId: v.string() },
66
- handler: async (ctx, args) => {
67
- return await ctx.db
68
- .query("purchases")
69
- .withIndex("by_agentId", (q) => q.eq("agentId", args.agentId))
70
- .collect();
71
- },
72
- });
73
- // Get active purchase for a provider
74
- export const getActivePurchase = query({
75
- args: {
76
- agentId: v.string(),
77
- providerId: v.string(),
78
- },
79
- handler: async (ctx, args) => {
80
- const purchases = await ctx.db
81
- .query("purchases")
82
- .withIndex("by_agentId_providerId", (q) => q.eq("agentId", args.agentId).eq("providerId", args.providerId))
83
- .collect();
84
- return purchases.find((p) => p.status === "active") || null;
85
- },
86
- });
87
- // Get usage for a purchase
88
- export const getUsage = query({
89
- args: { purchaseId: v.id("purchases") },
90
- handler: async (ctx, args) => {
91
- return await ctx.db
92
- .query("usage")
93
- .withIndex("by_purchaseId", (q) => q.eq("purchaseId", args.purchaseId))
94
- .first();
95
- },
96
- });
97
- // Record usage
98
- export const recordUsage = mutation({
99
- args: {
100
- purchaseId: v.id("purchases"),
101
- unitsUsed: v.number(),
102
- costUsd: v.number(),
103
- },
104
- handler: async (ctx, args) => {
105
- const usage = await ctx.db
106
- .query("usage")
107
- .withIndex("by_purchaseId", (q) => q.eq("purchaseId", args.purchaseId))
108
- .first();
109
- if (!usage) {
110
- throw new Error("Usage record not found");
111
- }
112
- const newUnitsRemaining = Math.max(0, usage.unitsRemaining - args.unitsUsed);
113
- await ctx.db.patch(usage._id, {
114
- unitsUsed: usage.unitsUsed + args.unitsUsed,
115
- unitsRemaining: newUnitsRemaining,
116
- costIncurredUsd: usage.costIncurredUsd + args.costUsd,
117
- lastUsedAt: Date.now(),
118
- });
119
- // Update purchase status if depleted
120
- if (newUnitsRemaining === 0) {
121
- const purchase = await ctx.db.get(args.purchaseId);
122
- if (purchase) {
123
- await ctx.db.patch(args.purchaseId, { status: "exhausted" });
124
- }
125
- }
126
- return await ctx.db
127
- .query("usage")
128
- .withIndex("by_purchaseId", (q) => q.eq("purchaseId", args.purchaseId))
129
- .first();
130
- },
131
- });
132
- // Get balance summary for an agent
133
- export const getBalanceSummary = query({
134
- args: { agentId: v.string() },
135
- handler: async (ctx, args) => {
136
- const credits = await ctx.db
137
- .query("agentCredits")
138
- .withIndex("by_agentId", (q) => q.eq("agentId", args.agentId))
139
- .first();
140
- const purchases = await ctx.db
141
- .query("purchases")
142
- .withIndex("by_agentId", (q) => q.eq("agentId", args.agentId))
143
- .collect();
144
- const activePurchases = purchases.filter((p) => p.status === "active");
145
- const totalSpent = purchases.reduce((sum, p) => sum + p.amountUsd, 0);
146
- return {
147
- credits: credits || {
148
- agentId: args.agentId,
149
- balanceUsd: 0,
150
- currency: "USD",
151
- },
152
- activePurchases,
153
- totalSpentUsd: totalSpent,
154
- };
155
- },
156
- });
157
- //# sourceMappingURL=purchases.js.map
@@ -1,4 +0,0 @@
1
- export declare const checkLimit: any;
2
- export declare const getUsage: any;
3
- export declare const cleanup: any;
4
- //# sourceMappingURL=ratelimit.d.ts.map
@@ -1,91 +0,0 @@
1
- import { mutation, query } from "./_generated/server";
2
- import { v } from "convex/values";
3
- // Rate limit config per tier
4
- const LIMITS = {
5
- free: {
6
- discovery: 100, // searches per hour
7
- instant: 10, // API calls per hour
8
- },
9
- subscriber: {
10
- discovery: 1000,
11
- instant: 100,
12
- },
13
- provider: {
14
- discovery: 10000,
15
- instant: 1000,
16
- },
17
- };
18
- // Check and increment rate limit
19
- export const checkLimit = mutation({
20
- args: {
21
- identifier: v.string(), // IP or agentId
22
- action: v.union(v.literal("discovery"), v.literal("instant")),
23
- tier: v.optional(v.union(v.literal("free"), v.literal("subscriber"), v.literal("provider"))),
24
- },
25
- handler: async (ctx, args) => {
26
- const tier = args.tier || "free";
27
- const limit = LIMITS[tier][args.action];
28
- const hourKey = Math.floor(Date.now() / 3600000); // Hour bucket
29
- const key = `${args.identifier}:${args.action}:${hourKey}`;
30
- // Get current count
31
- const existing = await ctx.db
32
- .query("rateLimits")
33
- .withIndex("by_key", (q) => q.eq("key", key))
34
- .first();
35
- if (existing) {
36
- if (existing.count >= limit) {
37
- return { allowed: false, remaining: 0, resetIn: 3600 - (Date.now() % 3600000) / 1000 };
38
- }
39
- await ctx.db.patch(existing._id, { count: existing.count + 1 });
40
- return { allowed: true, remaining: limit - existing.count - 1 };
41
- }
42
- // Create new entry
43
- await ctx.db.insert("rateLimits", {
44
- key,
45
- identifier: args.identifier,
46
- action: args.action,
47
- count: 1,
48
- hourBucket: hourKey,
49
- createdAt: Date.now(),
50
- });
51
- return { allowed: true, remaining: limit - 1 };
52
- },
53
- });
54
- // Get current usage stats
55
- export const getUsage = query({
56
- args: {
57
- identifier: v.string(),
58
- },
59
- handler: async (ctx, args) => {
60
- const hourKey = Math.floor(Date.now() / 3600000);
61
- const discovery = await ctx.db
62
- .query("rateLimits")
63
- .withIndex("by_key", (q) => q.eq("key", `${args.identifier}:discovery:${hourKey}`))
64
- .first();
65
- const instant = await ctx.db
66
- .query("rateLimits")
67
- .withIndex("by_key", (q) => q.eq("key", `${args.identifier}:instant:${hourKey}`))
68
- .first();
69
- return {
70
- discovery: discovery?.count || 0,
71
- instant: instant?.count || 0,
72
- limits: LIMITS.free,
73
- };
74
- },
75
- });
76
- // Cleanup old rate limit entries (run via cron)
77
- export const cleanup = mutation({
78
- args: {},
79
- handler: async (ctx) => {
80
- const hourAgo = Math.floor(Date.now() / 3600000) - 2; // Keep 2 hours
81
- const old = await ctx.db
82
- .query("rateLimits")
83
- .filter((q) => q.lt(q.field("hourBucket"), hourAgo))
84
- .take(100);
85
- for (const entry of old) {
86
- await ctx.db.delete(entry._id);
87
- }
88
- return { deleted: old.length };
89
- },
90
- });
91
- //# sourceMappingURL=ratelimit.js.map
@@ -1,13 +0,0 @@
1
- /**
2
- * Public mutation called by MCP server (path: searchLogs:log)
3
- */
4
- export declare const log: any;
5
- /**
6
- * Get recent searches for a workspace (path: searchLogs:getRecent)
7
- */
8
- export declare const getRecent: any;
9
- export declare const logSearch: any;
10
- export declare const getTopQueries: any;
11
- export declare const getStats: any;
12
- export declare const getZeroResultQueries: any;
13
- //# sourceMappingURL=searchLogs.d.ts.map
@@ -1,246 +0,0 @@
1
- import { internalMutation, mutation, query } from "./_generated/server";
2
- import { v } from "convex/values";
3
- /**
4
- * Public mutation called by MCP server (path: searchLogs:log)
5
- */
6
- export const log = mutation({
7
- args: {
8
- sessionToken: v.string(),
9
- query: v.string(),
10
- resultCount: v.number(),
11
- matchedProviders: v.optional(v.array(v.string())),
12
- responseTimeMs: v.optional(v.number()),
13
- subagentId: v.optional(v.string()),
14
- },
15
- handler: async (ctx, args) => {
16
- const session = await ctx.db
17
- .query("agentSessions")
18
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", args.sessionToken))
19
- .first();
20
- if (!session)
21
- return { success: false };
22
- await ctx.db.insert("searchLogs", {
23
- workspaceId: session.workspaceId,
24
- subagentId: args.subagentId,
25
- query: args.query,
26
- resultCount: args.resultCount,
27
- hasResults: args.resultCount > 0,
28
- matchedProviders: args.matchedProviders,
29
- responseTimeMs: args.responseTimeMs || 0,
30
- timestamp: Date.now(),
31
- });
32
- return { success: true };
33
- },
34
- });
35
- /**
36
- * Get recent searches for a workspace (path: searchLogs:getRecent)
37
- */
38
- export const getRecent = query({
39
- args: {
40
- token: v.string(),
41
- limit: v.optional(v.number()),
42
- },
43
- handler: async (ctx, { token, limit = 50 }) => {
44
- const session = await ctx.db
45
- .query("agentSessions")
46
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
47
- .first();
48
- if (!session)
49
- return [];
50
- const logs = await ctx.db
51
- .query("searchLogs")
52
- .withIndex("by_workspaceId", (q) => q.eq("workspaceId", session.workspaceId))
53
- .order("desc")
54
- .take(limit);
55
- return logs.map((l) => ({
56
- id: l._id,
57
- query: l.query,
58
- resultCount: l.resultCount,
59
- hasResults: l.hasResults,
60
- matchedProviders: l.matchedProviders || [],
61
- responseTimeMs: l.responseTimeMs,
62
- timestamp: l.timestamp,
63
- subagentId: l.subagentId,
64
- }));
65
- },
66
- });
67
- // Log a search query (uses existing searchLogs table schema)
68
- export const logSearch = internalMutation({
69
- args: {
70
- query: v.string(),
71
- resultsCount: v.number(),
72
- matchedProviders: v.optional(v.array(v.string())),
73
- sessionToken: v.optional(v.string()),
74
- userAgent: v.optional(v.string()),
75
- responseTimeMs: v.optional(v.number()),
76
- },
77
- handler: async (ctx, args) => {
78
- // Try to get workspaceId from session token
79
- let workspaceId = undefined;
80
- let subagentId = undefined;
81
- if (args.sessionToken) {
82
- try {
83
- const token = args.sessionToken;
84
- const session = await ctx.db
85
- .query("agentSessions")
86
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
87
- .first();
88
- if (session) {
89
- workspaceId = session.workspaceId;
90
- // No agentId in agentSessions, subagentId stays undefined
91
- }
92
- }
93
- catch (e) {
94
- // Ignore - just skip workspace linking
95
- }
96
- }
97
- // Only log if we have a workspace (existing schema requires it)
98
- if (workspaceId) {
99
- await ctx.db.insert("searchLogs", {
100
- workspaceId,
101
- subagentId,
102
- query: args.query,
103
- resultCount: args.resultsCount,
104
- hasResults: args.resultsCount > 0,
105
- matchedProviders: args.matchedProviders,
106
- responseTimeMs: args.responseTimeMs || 0,
107
- timestamp: Date.now(),
108
- });
109
- }
110
- // TODO: Also log anonymous searches somewhere (for product insights)
111
- },
112
- });
113
- // Get top search queries (for analytics)
114
- export const getTopQueries = query({
115
- args: {
116
- limit: v.optional(v.number()),
117
- since: v.optional(v.number()), // timestamp
118
- },
119
- handler: async (ctx, args) => {
120
- const limit = args.limit || 50;
121
- const since = args.since || Date.now() - 7 * 24 * 60 * 60 * 1000; // Last 7 days
122
- const logs = await ctx.db
123
- .query("searchLogs")
124
- .withIndex("by_timestamp")
125
- .filter((q) => q.gte(q.field("timestamp"), since))
126
- .collect();
127
- // Aggregate by query
128
- const queryCounts = {};
129
- for (const log of logs) {
130
- const q = log.query.toLowerCase().trim();
131
- if (!q)
132
- continue;
133
- if (!queryCounts[q]) {
134
- queryCounts[q] = { count: 0, avgResults: 0, totalResults: 0 };
135
- }
136
- queryCounts[q].count++;
137
- queryCounts[q].totalResults += log.resultCount;
138
- }
139
- // Calculate averages and sort
140
- const sorted = Object.entries(queryCounts)
141
- .map(([query, data]) => ({
142
- query,
143
- count: data.count,
144
- avgResults: Math.round(data.totalResults / data.count * 10) / 10,
145
- noResults: data.totalResults === 0,
146
- }))
147
- .sort((a, b) => b.count - a.count)
148
- .slice(0, limit);
149
- return {
150
- queries: sorted,
151
- totalSearches: logs.length,
152
- uniqueQueries: Object.keys(queryCounts).length,
153
- period: {
154
- since: new Date(since).toISOString(),
155
- until: new Date().toISOString(),
156
- },
157
- };
158
- },
159
- });
160
- // Get search stats for a workspace (path: searchLogs:getStats)
161
- export const getStats = query({
162
- args: {
163
- token: v.string(),
164
- hoursBack: v.optional(v.number()),
165
- },
166
- handler: async (ctx, { token, hoursBack }) => {
167
- // Try agentSessions first (MCP agent tokens)
168
- let workspaceId = null;
169
- const agentSession = await ctx.db
170
- .query("agentSessions")
171
- .withIndex("by_sessionToken", (q) => q.eq("sessionToken", token))
172
- .first();
173
- if (agentSession) {
174
- workspaceId = agentSession.workspaceId;
175
- }
176
- else {
177
- // Fall back to workspace magic-link sessions
178
- const wsSession = await ctx.db
179
- .query("workspaceSessions")
180
- .withIndex("by_token", (q) => q.eq("token", token))
181
- .first();
182
- if (wsSession)
183
- workspaceId = wsSession.workspaceId;
184
- }
185
- if (!workspaceId)
186
- return { totalSearches: 0, zeroResultSearches: 0, avgResponseTimeMs: 0, successRate: 0, byDay: [] };
187
- const since = hoursBack ? Date.now() - hoursBack * 60 * 60 * 1000 : 0;
188
- const logs = await ctx.db
189
- .query("searchLogs")
190
- .withIndex("by_workspaceId", (q) => q.eq("workspaceId", workspaceId))
191
- .collect();
192
- const filtered = since > 0 ? logs.filter((l) => l.timestamp >= since) : logs;
193
- const totalSearches = filtered.length;
194
- const zeroResultSearches = filtered.filter((l) => !l.hasResults).length;
195
- const avgResponseTimeMs = totalSearches > 0
196
- ? Math.round(filtered.reduce((sum, l) => sum + (l.responseTimeMs || 0), 0) / totalSearches)
197
- : 0;
198
- const successRate = totalSearches > 0
199
- ? Math.round(((totalSearches - zeroResultSearches) / totalSearches) * 1000) / 10
200
- : 0;
201
- // Per-day breakdown for chart
202
- const byDayMap = {};
203
- for (const log of filtered) {
204
- const day = new Date(log.timestamp).toISOString().split("T")[0];
205
- byDayMap[day] = (byDayMap[day] || 0) + 1;
206
- }
207
- const byDay = Object.entries(byDayMap)
208
- .map(([date, searches]) => ({ date, searches }))
209
- .sort((a, b) => a.date.localeCompare(b.date));
210
- return { totalSearches, zeroResultSearches, avgResponseTimeMs, successRate, byDay };
211
- },
212
- });
213
- // Get searches with no results (API gaps)
214
- export const getZeroResultQueries = query({
215
- args: {
216
- limit: v.optional(v.number()),
217
- since: v.optional(v.number()),
218
- },
219
- handler: async (ctx, args) => {
220
- const limit = args.limit || 20;
221
- const since = args.since || Date.now() - 7 * 24 * 60 * 60 * 1000;
222
- const logs = await ctx.db
223
- .query("searchLogs")
224
- .withIndex("by_hasResults")
225
- .filter((q) => q.and(q.eq(q.field("hasResults"), false), q.gte(q.field("timestamp"), since)))
226
- .collect();
227
- // Aggregate
228
- const queryCounts = {};
229
- for (const log of logs) {
230
- const q = log.query.toLowerCase().trim();
231
- if (!q)
232
- continue;
233
- queryCounts[q] = (queryCounts[q] || 0) + 1;
234
- }
235
- const sorted = Object.entries(queryCounts)
236
- .map(([query, count]) => ({ query, count }))
237
- .sort((a, b) => b.count - a.count)
238
- .slice(0, limit);
239
- return {
240
- gaps: sorted,
241
- totalZeroResults: logs.length,
242
- message: "These queries returned no results - potential APIs to add",
243
- };
244
- },
245
- });
246
- //# sourceMappingURL=searchLogs.js.map
@@ -1,7 +0,0 @@
1
- /**
2
- * Seed all 27 APILayer APIs for a workspace
3
- * Run with: npx convex run seedAPILayerAPIs:seedAll '{"email":"gustav_hemmingsson@hotmail.com"}'
4
- */
5
- export declare const cleanAndReseed: any;
6
- export declare const seedAll: any;
7
- //# sourceMappingURL=seedAPILayerAPIs.d.ts.map