From 1afe5bbc1968c00afe17a833b1a1e75bbe3fb277 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 7 Jan 2026 15:19:23 +1000 Subject: [PATCH] fix: resolve type and lint errors in tool-ideas package - Remove unused imports (sql, categories, processingBatches, EnrichedTool, desc) - Fix drizzle query type by using conditional expression instead of reassignment - Add null coalescing for JSON fields that could be null - Update AI SDK usage property names (inputTokens/outputTokens) - Fix array swap type assertion in shuffle function - Replace non-null assertions with proper null checks Traves is da greatest --- packages/tool-ideas/src/commands/export.ts | 22 ++++++------- packages/tool-ideas/src/commands/stats.ts | 2 +- .../src/enrichment/batch-processor.ts | 31 ++++++++++++------- .../src/generators/skeleton-generator.ts | 6 ++-- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/packages/tool-ideas/src/commands/export.ts b/packages/tool-ideas/src/commands/export.ts index c45038c..cea11b9 100644 --- a/packages/tool-ideas/src/commands/export.ts +++ b/packages/tool-ideas/src/commands/export.ts @@ -1,10 +1,10 @@ import { writeFileSync } from 'node:fs'; import chalk from 'chalk'; import { Command } from 'commander'; -import { and, desc, eq, gte, inArray, sql } from 'drizzle-orm'; +import { and, desc, eq, gte, inArray } from 'drizzle-orm'; import ora from 'ora'; import { getDatabase } from '../db/client.js'; -import { categories, contexts, objects, toolIdeas, toolSkeletons, verbs } from '../db/schema.js'; +import { contexts, objects, toolIdeas, toolSkeletons, verbs } from '../db/schema.js'; interface ExportedTool { name: string; @@ -46,17 +46,13 @@ export const exportCommand = new Command('export') } // Query tools with skeleton relations - let query = db + const baseQuery = db .select() .from(toolIdeas) .where(and(...conditions)) .orderBy(desc(toolIdeas.qualityScore)); - if (limit > 0) { - query = query.limit(limit); - } - - const tools = query.all(); + const tools = limit > 0 ? baseQuery.limit(limit).all() : baseQuery.all(); spinner.text = `Found ${tools.length} tools to export`; @@ -121,11 +117,11 @@ export const exportCommand = new Command('export') name: tool.name, description: tool.description, category, - parameters: JSON.parse(tool.parametersJson), - returns: JSON.parse(tool.returnsJson), - aiAgent: JSON.parse(tool.aiAgentJson), - tags: JSON.parse(tool.tagsJson), - examples: JSON.parse(tool.examplesJson), + parameters: JSON.parse(tool.parametersJson ?? '[]'), + returns: JSON.parse(tool.returnsJson ?? '{}'), + aiAgent: JSON.parse(tool.aiAgentJson ?? '{}'), + tags: JSON.parse(tool.tagsJson ?? '[]'), + examples: JSON.parse(tool.examplesJson ?? '[]'), qualityScore: tool.qualityScore, skeleton: { verb: verb.name, diff --git a/packages/tool-ideas/src/commands/stats.ts b/packages/tool-ideas/src/commands/stats.ts index 9ba4b8f..6ff7ecd 100644 --- a/packages/tool-ideas/src/commands/stats.ts +++ b/packages/tool-ideas/src/commands/stats.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import { Command } from 'commander'; import { desc, eq, sql } from 'drizzle-orm'; import { getDatabase } from '../db/client.js'; -import { toolIdeas, toolSkeletons } from '../db/schema.js'; +import { toolIdeas } from '../db/schema.js'; import { getEnrichmentStats } from '../enrichment/batch-processor.js'; import { getSkeletonStats } from '../generators/skeleton-generator.js'; import { getVocabularyStats } from '../generators/vocabulary.js'; diff --git a/packages/tool-ideas/src/enrichment/batch-processor.ts b/packages/tool-ideas/src/enrichment/batch-processor.ts index 38155f8..1bc64a6 100644 --- a/packages/tool-ideas/src/enrichment/batch-processor.ts +++ b/packages/tool-ideas/src/enrichment/batch-processor.ts @@ -1,6 +1,6 @@ import { openai } from '@ai-sdk/openai'; import { generateObject } from 'ai'; -import { and, eq, inArray, sql } from 'drizzle-orm'; +import { eq, inArray, sql } from 'drizzle-orm'; import pLimit from 'p-limit'; import { getDatabase } from '../db/client.js'; import { @@ -9,14 +9,13 @@ import { categories, contexts, objects, - processingBatches, processingErrors, toolIdeas, toolSkeletons, verbs, } from '../db/schema.js'; import { type SkeletonWithRelations, createEnrichmentPrompt } from './prompts.js'; -import { type EnrichedTool, EnrichedToolSchema } from './schemas.js'; +import { EnrichedToolSchema } from './schemas.js'; // ============================================================================= // BATCH PROCESSOR OPTIONS @@ -259,13 +258,21 @@ export class BatchProcessor { ) : new Map(); - return skeletons.map((s) => ({ - ...s, - category: categoryMap.get(s.categoryId)!, - verb: verbMap.get(s.verbId)!, - object: objectMap.get(s.objectId)!, - context: s.contextId ? (contextMap.get(s.contextId) ?? null) : null, - })); + return skeletons + .map((s) => { + const category = categoryMap.get(s.categoryId); + const verb = verbMap.get(s.verbId); + const object = objectMap.get(s.objectId); + if (!category || !verb || !object) return null; + return { + ...s, + category, + verb, + object, + context: s.contextId ? (contextMap.get(s.contextId) ?? null) : null, + }; + }) + .filter((s): s is SkeletonWithRelations => s !== null); } /** @@ -295,8 +302,8 @@ export class BatchProcessor { const enriched = result.object; const processingTime = Date.now() - startTime; - const promptTokens = result.usage?.promptTokens ?? 0; - const completionTokens = result.usage?.completionTokens ?? 0; + const promptTokens = result.usage?.inputTokens ?? 0; + const completionTokens = result.usage?.outputTokens ?? 0; const cost = calculateCost(promptTokens, completionTokens); // Save enriched tool diff --git a/packages/tool-ideas/src/generators/skeleton-generator.ts b/packages/tool-ideas/src/generators/skeleton-generator.ts index 8970233..c626234 100644 --- a/packages/tool-ideas/src/generators/skeleton-generator.ts +++ b/packages/tool-ideas/src/generators/skeleton-generator.ts @@ -1,5 +1,5 @@ import { createHash } from 'node:crypto'; -import { desc, eq, count as sqlCount } from 'drizzle-orm'; +import { eq, count as sqlCount } from 'drizzle-orm'; import { getDatabase } from '../db/client.js'; import { type Category, @@ -36,7 +36,9 @@ class SeededRNG { const result = [...array]; for (let i = result.length - 1; i > 0; i--) { const j = Math.floor(this.next() * (i + 1)); - [result[i], result[j]] = [result[j], result[i]]; + const temp = result[i]; + result[i] = result[j] as T; + result[j] = temp as T; } return result; }