11import { useState } from "react" ;
2- import { useTeams } from "../../features/agents/react" ;
3- import type { Agents , Team } from "../../features/agents/service" ;
2+ import { useAgentsSnapshot , useTeams } from "../../features/agents/react" ;
3+ import type { Agent , Agents , Team } from "../../features/agents/service" ;
44import {
55 channelTemplates ,
66 useChannelTemplates ,
@@ -19,7 +19,7 @@ import { SettingsGroup } from "../../shared/design-system/ui/SettingsGroup";
1919import { Textarea } from "../../shared/design-system/ui/Textarea" ;
2020import styles from "./ChannelTemplates.module.css" ;
2121
22- /** Templates a new channel can start from: its teams and its Canvas. */
22+ /** Templates a new channel can start from: its agents, teams and Canvas. */
2323export function ChannelTemplateSettings ( {
2424 agents,
2525 active,
@@ -29,6 +29,7 @@ export function ChannelTemplateSettings({
2929} ) {
3030 const templates = useChannelTemplates ( ) ;
3131 const teams = useTeams ( agents ) ;
32+ const choices = useAgentsSnapshot ( agents ) ?. agents ?? noAgents ;
3233 // A template's id while it is edited, or "new" for one being made.
3334 const [ editing , setEditing ] = useState < string > ( ) ;
3435 const template = templates . find ( ( item ) => item . id === editing ) ;
@@ -45,7 +46,7 @@ export function ChannelTemplateSettings({
4546 < PreferenceRow
4647 key = { item . id }
4748 title = { item . name }
48- subtitle = { summary ( item , teams ) }
49+ subtitle = { summary ( item , choices , teams ) }
4950 trailing = {
5051 < Button
5152 aria-label = { `Edit ${ item . name } ` }
@@ -69,13 +70,14 @@ export function ChannelTemplateSettings({
6970 < EmptyState
7071 icon = { < CopyIcon /> }
7172 title = "No channel templates yet"
72- description = "Start new channels with your teams and a Canvas already in place."
73+ description = "Start new channels with your agents, teams and a Canvas already in place."
7374 action = { < Button onClick = { newTemplate } > New template</ Button > }
7475 />
7576 ) }
7677 { ( editing === "new" || template ) && (
7778 < TemplateDialog
7879 key = { editing }
80+ agents = { choices }
7981 teams = { teams }
8082 { ...( template ? { template } : { } ) }
8183 onClose = { ( ) => setEditing ( undefined ) }
@@ -85,10 +87,21 @@ export function ChannelTemplateSettings({
8587 ) ;
8688}
8789
88- function summary ( template : ChannelTemplate , teams : readonly Team [ ] ) {
89- const names = template . teams . flatMap (
90- ( id ) => teams . find ( ( team ) => team . id === id ) ?. name ?? [ ] ,
91- ) ;
90+ const noAgents : readonly never [ ] = Object . freeze ( [ ] ) ;
91+
92+ function summary (
93+ template : ChannelTemplate ,
94+ agents : readonly Agent [ ] ,
95+ teams : readonly Team [ ] ,
96+ ) {
97+ const names = [
98+ ...template . agents . flatMap (
99+ ( pubkey ) => agents . find ( ( agent ) => agent . pubkey === pubkey ) ?. name ?? [ ] ,
100+ ) ,
101+ ...template . teams . flatMap (
102+ ( id ) => teams . find ( ( team ) => team . id === id ) ?. name ?? [ ] ,
103+ ) ,
104+ ] ;
92105 return (
93106 [ names . join ( ", " ) , template . canvas . trim ( ) ? "Canvas" : "" ]
94107 . filter ( Boolean )
@@ -97,15 +110,20 @@ function summary(template: ChannelTemplate, teams: readonly Team[]) {
97110}
98111
99112function TemplateDialog ( {
113+ agents,
100114 teams,
101115 template,
102116 onClose,
103117} : {
118+ agents : readonly Agent [ ] ;
104119 teams : readonly Team [ ] ;
105120 template ?: ChannelTemplate ;
106121 onClose ( ) : void ;
107122} ) {
108123 const [ name , setName ] = useState ( template ?. name ?? "" ) ;
124+ const [ chosenAgents , setChosenAgents ] = useState < readonly string [ ] > (
125+ template ?. agents ?? [ ] ,
126+ ) ;
109127 const [ chosen , setChosen ] = useState < readonly string [ ] > (
110128 template ?. teams ?? [ ] ,
111129 ) ;
@@ -159,6 +177,7 @@ function TemplateDialog({
159177 ...( template ? { id : template . id } : { } ) ,
160178 name,
161179 teams : chosen ,
180+ agents : chosenAgents ,
162181 canvas,
163182 } ) ,
164183 ) ;
@@ -171,6 +190,27 @@ function TemplateDialog({
171190 onChange = { ( event ) => setName ( event . target . value ) }
172191 />
173192 </ Field >
193+ < fieldset className = { styles . teams } >
194+ < legend className = "text-label-sm" > Agents</ legend >
195+ { agents . length ? (
196+ agents . map ( ( agent ) => (
197+ < Checkbox
198+ key = { agent . pubkey }
199+ label = { agent . name }
200+ checked = { chosenAgents . includes ( agent . pubkey ) }
201+ onCheckedChange = { ( checked ) =>
202+ setChosenAgents ( ( last ) =>
203+ checked
204+ ? [ ...last , agent . pubkey ]
205+ : last . filter ( ( pubkey ) => pubkey !== agent . pubkey ) ,
206+ )
207+ }
208+ />
209+ ) )
210+ ) : (
211+ < p className = "m-0 text-body-sm text-secondary" > No agents yet.</ p >
212+ ) }
213+ </ fieldset >
174214 < fieldset className = { styles . teams } >
175215 < legend className = "text-label-sm" > Teams</ legend >
176216 { teams . length ? (
0 commit comments