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
This commit is contained in:
Ajax Davis 2026-01-07 15:19:23 +10:00
parent 0cbc3e0dd4
commit 1afe5bbc19
4 changed files with 33 additions and 28 deletions

View file

@ -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,

View file

@ -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';

View file

@ -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

View file

@ -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;
}