Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/clef

Cloudflare Clef decision models via Workers AI (Jev-shaped noul/choice/score API).

FollowFork

Files

index.ts

103 lines · 3.7 KB · TypeScript
/**
 * Overview and setup checklist for Cloudflare Clef via Workers AI.
 * Use when an agent needs setup URLs or readiness before calling `./evaluate` or `./run-toward-goal`.
 *
 * @returns Safe setup checklist (no secrets). Prefer `./evaluate` for real calls.
 *
 * @example
 * import overview from 'kody:@kody/clef'
 * const status = await overview()
 */

import { missingSetup, secretsNewUrl } from './resolve.ts'
import clefSettings from './settings.ts'

/**
 * Overview and setup checklist for Cloudflare Clef via Workers AI.
 * Use when an agent needs setup URLs or readiness before calling `./evaluate` or `./run-toward-goal`.
 *
 * @returns Safe setup checklist (no secrets). Prefer `./evaluate` for real calls.
 *
 * @example
 * import overview from 'kody:@kody/clef'
 * const status = await overview()
 */
export default async function overview() {
	const settings = await clefSettings()
	const ready = Boolean(
		settings && typeof settings === 'object' && 'accountId' in settings
			? (settings as { accountId?: string }).accountId
			: false,
	)
	const model =
		settings && typeof settings === 'object' && 'model' in settings
			? (settings as { model?: string }).model
			: undefined
	const gatewayId =
		settings && typeof settings === 'object' && 'gatewayId' in settings
			? (settings as { gatewayId?: string }).gatewayId
			: undefined
	const sources =
		settings && typeof settings === 'object' && 'sources' in settings
			? (settings as { sources?: unknown }).sources
			: undefined
	const bodyModel =
		settings && typeof settings === 'object' && 'bodyModel' in settings
			? (settings as { bodyModel?: string }).bodyModel
			: undefined

	return {
		package: '@kody/clef',
		intent:
			'Call Cloudflare Clef (@cf/cloudflare/clef-flash / clef) structured evaluations through Workers AI — including picking the next state-machine transition from enabled events and walking a declarative machine toward a goal — reusing the same cloudflareApiToken and account/gateway as @kentcdodds/ai or @kentcdodds/jev when possible.',
		exports: [
			'.',
			'./evaluate',
			'./choose-transition',
			'./run-toward-goal',
			'./build-choice-from-events',
			'./request',
			'./settings',
			'./types',
			'./smoke-test',
		],
		model,
		bodyModel,
		ready,
		settings: {
			accountIdSet: ready,
			gatewayId,
			model,
			bodyModel,
			sources,
		},
		secret: 'cloudflareApiToken',
		secretsNewUrl,
		docs: {
			clefFlash: 'https://developers.cloudflare.com/workers-ai/models/clef-flash/',
			clef: 'https://developers.cloudflare.com/workers-ai/models/clef/',
			changelog:
				'https://developers.cloudflare.com/changelog/post/2026-10-01-clef-workers-ai/',
			package: 'https://kody.codes/@kody/clef',
			jevSibling: 'https://kody.codes/@kentcdodds/jev',
		},
		setup: ready ? undefined : missingSetup(''),
		next: ready
			? 'import evaluate from "kody:@kody/clef/evaluate"'
			: 'Save cloudflareApiToken, then set accountId via ./settings (or reuse @kentcdodds/ai/settings / @kentcdodds/jev/settings).',
		vsJev: {
			body: 'Flat { model, state, questions } — not Jev { model, input: { state, questions } }',
			url: 'POST .../ai/run/@cf/cloudflare/clef-flash (model in path)',
			defaultModel: '@cf/cloudflare/clef-flash (body model: clef-flash)',
			billing: 'Workers AI (not TypeSafe BYOK / third-party gateway model)',
		},
	}
}

export { default as evaluate } from './evaluate.ts'
export { default as clefRequest } from './request.ts'
export { default as clefSettings } from './settings.ts'
export { default as smokeTest } from './smoke-test.ts'
export { default as chooseTransition } from './choose-transition.ts'
export { default as runTowardGoal } from './run-toward-goal.ts'
export { default as buildChoiceFromEvents } from './build-choice-from-events.ts'