Community packages

@kentcdodds/ai

by @kentcdodds

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

  • ai
  • chat
  • agent
  • turns
  • tools
  • gateway
License
MIT
Published
7/9/2026
Pinned commit
78b9e8f
Rating
No ratings yet
Adaptation effort
Forks
0

Fork with your agent

Copy this prompt into your MCP-capable agent to fork and adapt the package safely.

Use Kody to fork the community package "@kentcdodds/ai" (listing id: d9939813-c762-42ff-8aae-d6f4413ac528). Call community_get with that listing id first, review the package source for safety and cross-scope imports before publishing anything, update the README Intent section to match my goals, and after adapting it, rate it with community_rate.

README

# @kentcdodds/ai

## Intent

Hosted AI chat app and package-first generic Kody agent turns. Runs a tool loop (Kody `search` and `execute`) with OpenAI-compatible chat calls routed through the Cloudflare AI Gateway (`cloudflareAiGatewayId` user value; auto-resolved or created as gateway `kody` on first run).

## When To Use

- Run a single tool-using agent turn from Discord chat, email automation, or another package harness.
- Stream or poll buffered turn events (`assistant_delta`, `tool_call_*`, `turn_complete`) for UI or workflow glue.
- Open the hosted HTML chat app for a quick manual turn (`open_generated_ui({ kody_id: 'ai' })`).
- Start a storage-backed background turn when a workflow needs `start` / `readNext` / `cancel` semantics.
- Import `./turn` directly when you only need the engine without the root wrapper.

## Required setup

- User-scoped `cloudflareApiToken` secret and `cloudflareAccountId` value.
- Optional `cloudflareAiModel` value (defaults to `@cf/mistralai/mistral-small-3.1-24b-instruct`).
- Optional `cloudflareAiGatewayId` value; auto-created as gateway `kody` when the token can manage AI Gateway.
- Package storage and workflows runtime for `./runs` background polling (provided by Kody when the package app/jobs run).

## Exports

- `kody:@kentcdodds/ai` — default `agentChatTurn`; also `agentTurnStream`, `startAgentTurn`, `readNextAgentTurnEvents`, `cancelAgentTurn`.
- `kody:@kentcdodds/ai/turn` — merged agent-turn engine (`runAgentTurn` default export).
- `kody:@kentcdodds/ai/app` — hosted fetch handler (GET form, POST one turn as JSON events).
- `kody:@kentcdodds/ai/runs` — storage-backed turn start, poll, cancel, and `runStoredAgentTurn` worker default export.
- `kody:@kentcdodds/ai/types` — `AgentTurnInput`, `AgentTurnResult`, `AgentTurnStreamEvent`, and related types.

`agentTurnStream` awaits the full turn then yields at most one `assistant_delta` plus `turn_complete` (not incremental token streaming). `modelLane` on input is accepted but currently ignored.

## Example

```ts
import { agentTurnStream } from 'kody:@kentcdodds/ai'

export default async function main() {
	let answer = ''
	for await (const event of agentTurnStream({
		messages: [{ role: 'user', content: 'Search for weather helpers' }],
	})) {
		if (event.type === 'assistant_delta') answer += event.text
		if (event.type === 'turn_complete') return { answer: event.assistantText, tools: event.toolCalls }
	}
	return { answer }
}
```

Report this listing

Log in to report this listing.