Thinking steps
An assistant’s reasoning and tool calls as a trace that opens while it runs and says how long it took.
Previews are drawn in the theme you made.
Edit itDone #
- Planned the answer done 0.9s
- Found four sources on tide tables.
- Read the sources done 1.1s
import { Bundles, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Shut once done, saying how long it took; a press opens it. Whether it is
// open is the Bundle's Model: none follows the work, and a press keeps what
// the reader asked for.
export default example({
title: 'Done',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
state: Bundles.ThinkingSteps.with({}),
view: ({ style, model, onMessage, h }) =>
h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
ThinkingSteps.view(
{
id: 'steps-basic',
steps: [
{ id: 'plan', title: 'Planned the answer', state: 'done', duration: 900 },
{
id: 'search',
title: 'Searched the web',
state: 'done',
duration: 2300,
detail: 'Found four sources on tide tables.',
},
{ id: 'read', title: 'Read the sources', state: 'done', duration: 1100 },
],
...ThinkingSteps.controls(model, onMessage),
style,
},
h,
),
],
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Running #
- Searched the web done 2.3s
- Fetching tides.example failed 0.4s
- Check the cache skipped
- Reading 3 sources running
- Write the answer pending
import { Bundles, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Open while it runs, its summary the running step's title, shimmering. A
// skipped step counts as finished and says so in words.
export default example({
title: 'Running',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
state: Bundles.ThinkingSteps.with({}),
view: ({ style, model, onMessage, h }) =>
h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
ThinkingSteps.view(
{
id: 'steps-running',
steps: [
{ id: 'search', title: 'Searched the web', state: 'done', duration: 2300 },
{ id: 'fetch', title: 'Fetching tides.example', state: 'failed', duration: 400 },
{ id: 'cache', title: 'Check the cache', state: 'skipped' },
{ id: 'read', title: 'Reading 3 sources', state: 'running' },
{ id: 'write', title: 'Write the answer', state: 'pending' },
],
...ThinkingSteps.controls(model, onMessage),
style,
},
h,
),
],
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Tool calls #
→ { "city": "Lisbon" }
← { "high": 24, "sky": "clear" }→ { "day": "Saturday" }
← 2 events- Work calendar done 0.5s
- Home calendar done 0.7s
import { Bundles, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// Each tool call's input and output under its own row, which a press shows
// and hides: `multiple` is the Bundle's arg, so any number are open.
export default example({
title: 'Tool calls',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
pins: { variant: 'card' },
state: Bundles.ThinkingSteps.with({ openSteps: ['weather'], multiple: true }),
view: ({ style, model, onMessage, h }) => {
const call = (input: string, output: string) =>
h.pre(
[h.Style({ margin: '0', whiteSpace: 'pre-wrap', fontSize: '0.8125rem' })],
[`→ ${input}`, h.br([]), `← ${output}`],
)
return h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
ThinkingSteps.view(
{
id: 'steps-tools',
summary: 'Used 2 tools',
steps: [
{
id: 'weather',
title: 'get_weather',
state: 'done',
duration: 640,
detail: call('{ "city": "Lisbon" }', '{ "high": 24, "sky": "clear" }'),
},
{
id: 'calendar',
title: 'list_events',
state: 'done',
duration: 1200,
detail: call('{ "day": "Saturday" }', '2 events'),
steps: [
{ id: 'calendar-work', title: 'Work calendar', state: 'done', duration: 500 },
{ id: 'calendar-home', title: 'Home calendar', state: 'done', duration: 700 },
],
},
],
...ThinkingSteps.controls(model, onMessage),
style,
},
h,
),
],
)
},
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Sources as links #
- Tide, Wikipedia doneThe moon and the sun raise the tides.
- Spring tides follow a full or new moon.
- They agree.
import { Bundles, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A step with an `href` is a link, as a citation or a source is: such a step
// is no toggle, so its detail always shows. The rest still open and shut.
export default example({
title: 'Sources as links',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
state: Bundles.ThinkingSteps.with({}),
view: ({ style, model, onMessage, h }) =>
h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
ThinkingSteps.view(
{
id: 'steps-sources',
summary: 'Read 2 sources',
steps: [
{
id: 'tides',
title: 'Tide, Wikipedia',
state: 'done',
href: 'https://en.wikipedia.org/wiki/Tide',
detail: 'The moon and the sun raise the tides.',
},
{
id: 'moon',
title: 'Lunar phase, Wikipedia',
state: 'done',
href: 'https://en.wikipedia.org/wiki/Lunar_phase',
detail: 'Spring tides follow a full or new moon.',
},
{ id: 'notes', title: 'Cross-checked the two', state: 'done', detail: 'They agree.' },
],
...ThinkingSteps.controls(model, onMessage),
style,
},
h,
),
],
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
A flat list with an action #
- Install done 4.2s
- Test failed 9.1s
- Publish skipped
import { Option, Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Button, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Again = Recipes.Button.style({ size: 'sm', variant: 'outline' })
const Model = Schema.Struct({ retried: Schema.Boolean })
const Message = defineMessageUnion({ Retried: {} })
// `trigger: 'none'` draws the steps alone, a list that does not shut. A
// step's `trailing` stands beside its row, outside its button: here the
// action that retries the one that failed.
export default example({
title: 'A flat list with an action',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
state: {
Model,
Message,
init: () => ({ model: { retried: false } }),
update: (model, message) =>
Message.match(message, {
Retried: () => (model.retried ? { model } : { model: { retried: true } }),
}),
},
view: ({ style, model, onMessage, h }) =>
h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
ThinkingSteps.view(
{
id: 'steps-flat',
trigger: 'none',
open: Option.none(),
onToggle: () => onMessage(Message.Retried()),
words: { steps: 'Build steps' },
steps: [
{ id: 'install', title: 'Install', state: 'done', duration: 4200 },
model.retried
? { id: 'test', title: 'Test', state: 'running' }
: {
id: 'test',
title: 'Test',
state: 'failed',
duration: 9100,
trailing: Button.view(
{ label: 'Retry', onClick: onMessage(Message.Retried()), style: Again },
h,
),
},
{ id: 'publish', title: 'Publish', state: 'skipped' },
],
style,
},
h,
),
],
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Configure once #
- Suchen fertig 1.8s
- Lesen fertig 2.4s
import { Bundles, Recipes, ThinkingSteps, ThinkingStepsSlots } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Cards = Recipes.ThinkingSteps.style({ variant: 'card' })
// What every trace of an application starts from: its look and its words in
// its language. Which steps are open stays the Bundle's.
const AppSteps = ThinkingSteps.configure({
base: {
style: Cards,
words: {
thinking: 'Denkt nach',
thoughtFor: 'Nachgedacht, {time}',
done: 'fertig',
running: 'läuft',
pending: 'wartet',
},
},
})
export default example({
title: 'Configure once',
slots: ThinkingStepsSlots,
recipe: Recipes.ThinkingSteps,
state: Bundles.ThinkingSteps.with({}),
view: ({ model, onMessage, h }) =>
h.div(
[h.Style({ inlineSize: 'min(28rem, 100%)' })],
[
AppSteps.view(
{
id: 'steps-configure',
steps: [
{ id: 'a', title: 'Suchen', state: 'done', duration: 1800 },
{ id: 'b', title: 'Lesen', state: 'done', duration: 2400 },
],
...ThinkingSteps.controls(model, onMessage),
},
h,
),
],
),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.