refactor: remove Workers AI as any with proper type definitions

- Add WorkersAIModel, WorkersAITextGenerationInput/Output types
- Remove `as any` from summary-service.ts (4 instances)
- Remove `as any` from bank-sms-parser.ts (3 instances)
- Remove `as any` from n8n-service.ts (2 instances)
- Add OpenAIResponse interface for API responses

Type-safe Workers AI calls with full IntelliSense support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-19 23:42:17 +09:00
parent 61e5185916
commit a2cb4ce686
4 changed files with 64 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import { z } from 'zod';
import { Env, IntentAnalysis, N8nResponse } from './types';
import { Env, IntentAnalysis, N8nResponse, WorkersAITextGenerationOutput, WorkersAITextGenerationInput } from './types';
import { createLogger } from './utils/logger';
const logger = createLogger('n8n-service');
@@ -53,10 +53,14 @@ ${userMessage}
JSON:`;
try {
const response = await ai.run('@cf/meta/llama-3.1-8b-instruct' as any, {
const input: WorkersAITextGenerationInput = {
messages: [{ role: 'user', content: prompt }],
max_tokens: 100,
}) as any;
};
const response = await ai.run(
'@cf/meta/llama-3.1-8b-instruct' as '@cf/meta/llama-3.1-8b-instruct-fp8',
input
) as WorkersAITextGenerationOutput;
const text = response.response || '';