Skip to content
← Public packages

@kentcdodds/ai

Kody tool-using agent turns with Vercel AI SDK and Cloudflare AI Gateway.

src/types.ts

24 lines · 2.3 KB · TypeScript
import { migrateAiFromValues, readLocalSetting } from './legacy-value.ts'

export type AgentTurnMessage = { role: 'system' | 'user' | 'assistant'; content: string; cache?: 'prefix' }
export type AgentTurnInput = { messages: Array<AgentTurnMessage>; system?: string | { content: string; cache?: 'prefix' }; sessionId?: string; maxSteps?: number; modelId?: string; modelLane?: string; conversationId?: string; memoryContext?: { task?: string; query?: string; entities?: string[]; constraints?: string[] } }
export type AgentToolTrace = { id: string; toolName: string; input: unknown; output?: unknown; error?: string }
export type AgentTurnResult = { assistantText: string; reasoningText?: string; summary?: string | null; continueRecommended?: boolean; needsUserInput?: boolean; stepsUsed?: number; newInformation?: boolean; stopReason?: string; finishReason?: string; toolCalls?: Array<AgentToolTrace>; conversationId?: string; text?: string; response?: string; error?: string }
export type AgentTurnStreamEvent = { type: 'assistant_delta'; text: string } | { type: 'reasoning_delta'; text: string } | { type: 'tool_call_started'; id: string; toolName: string; input: unknown } | { type: 'tool_call_finished'; id: string; toolName: string; input: unknown; output?: unknown; error?: string } | ({ type: 'turn_complete' } & AgentTurnResult) | { type: 'error'; message: string; phase: string }
export type AgentChatTurnOutput = { ok: boolean; result?: AgentTurnResult; error?: string; events?: Array<AgentTurnStreamEvent> }
export type AgentTurnStartOutput = { ok: true; runId: string; sessionId: string; conversationId: string }
export type AgentTurnNextOutput = { ok: true; events: Array<AgentTurnStreamEvent>; nextCursor: number; done: boolean }
export type AgentTurnCancelOutput = { ok: true; cancelled: boolean }

/** Type metadata overview for ai agent turn inputs, outputs, and stream events. */
export default async function describeAiTypes() {
	const migrate = await migrateAiFromValues()
	return {
		packageId: 'ai',
		exportName: './types',
		description: 'Type metadata for ai agent turn inputs, outputs, and stream events.',
		migrate,
		accountIdPresent: Boolean(await readLocalSetting('cloudflareAccountId')),
		gatewayIdPresent: Boolean(await readLocalSetting('cloudflareAiGatewayId')),
	}
}