///
import {
Cell,
computed,
generateObject,
pattern,
patternTool,
toSchema,
UI,
type WishState,
} from "commontools";
import { fetchAndRunPattern, listPatternIndex } from "./common-tools.tsx";
export default pattern<
{ situation: string; context: { [id: string]: any } },
WishState| >
>(({ situation, context }) => {
const suggestion = generateObject({
system: "Find a useful pattern, run it, pass link to final result",
prompt: situation,
context,
tools: {
fetchAndRunPattern: patternTool(fetchAndRunPattern),
listPatternIndex: patternTool(listPatternIndex),
},
model: "anthropic:claude-haiku-4-5",
schema: toSchema<{ cell: Cell }>(),
});
const result = computed(() => suggestion.result?.cell);
return {
result,
[UI]: (
{computed(() => result ?? "Searching...")}
),
};
});
|