11import { PiIcon } from '@/components/icons'
22import { getEnv , isTruthy } from '@/lib/core/config/env'
3+ import {
4+ isPiByokOnlyMode ,
5+ PI_CLOUD_AUTHORING_MODES ,
6+ PI_CLOUD_MODES ,
7+ PI_CONTEXTUAL_MODES ,
8+ PI_MODE_DEFINITIONS ,
9+ PI_MODE_IDS ,
10+ } from '@/lib/pi/modes'
311import type { BlockConfig } from '@/blocks/types'
412import { AuthMode , IntegrationType } from '@/blocks/types'
513import {
@@ -8,7 +16,6 @@ import {
816 getProviderCredentialSubBlocks ,
917 PROVIDER_CREDENTIAL_INPUTS ,
1018} from '@/blocks/utils'
11- import { isPiByokOnlyMode } from '@/providers/pi-providers'
1219import type { ToolResponse } from '@/tools/types'
1320
1421interface PiResponse extends ToolResponse {
@@ -59,11 +66,11 @@ const CLOUD_ANY: {
5966 value : Array < 'cloud' | 'cloud_branch' | 'cloud_review' >
6067} = {
6168 field : 'mode' ,
62- value : [ 'cloud' , 'cloud_branch' , 'cloud_review' ] ,
69+ value : [ ... PI_CLOUD_MODES ] ,
6370}
6471const CLOUD_AUTHORING : { field : 'mode' ; value : Array < 'cloud' | 'cloud_branch' > } = {
6572 field : 'mode' ,
66- value : [ 'cloud' , 'cloud_branch' ] ,
73+ value : [ ... PI_CLOUD_AUTHORING_MODES ] ,
6774}
6875const BABYSIT_ENABLED_VALUES : Array < true | 'true' > = [ true , 'true' ]
6976const CLOUD_WITH_BABYSIT : {
@@ -72,7 +79,7 @@ const CLOUD_WITH_BABYSIT: {
7279 and : { field : 'babysitMode' ; value : Array < true | 'true' > }
7380} = {
7481 field : 'mode' ,
75- value : [ 'cloud' , 'cloud_branch' ] ,
82+ value : [ ... PI_CLOUD_AUTHORING_MODES ] ,
7683 and : { field : 'babysitMode' , value : BABYSIT_ENABLED_VALUES } ,
7784}
7885function getCloudWithoutBabysitCondition ( values ?: Record < string , unknown > ) : {
@@ -106,12 +113,12 @@ function getCloudBranchWithoutBabysitCondition(values?: Record<string, unknown>)
106113 }
107114}
108115const LOCAL : { field : 'mode' ; value : 'local' } = { field : 'mode' , value : 'local' }
109- const AUTHORING_MODES : {
116+ const CONTEXTUAL_MODES : {
110117 field : 'mode'
111118 value : Array < 'cloud' | 'cloud_branch' | 'local' >
112119} = {
113120 field : 'mode' ,
114- value : [ 'cloud' , 'cloud_branch' , 'local' ] ,
121+ value : [ ... PI_CONTEXTUAL_MODES ] ,
115122}
116123const MEMORY_TYPES = [ 'conversation' , 'sliding_window' , 'sliding_window_tokens' ]
117124
@@ -182,35 +189,15 @@ export const PiBlock: BlockConfig<PiResponse> = {
182189 type : 'dropdown' ,
183190 /** Cloud modes require E2B and stay hidden when it is disabled. */
184191 value : ( ) => ( isTruthy ( getEnv ( 'NEXT_PUBLIC_E2B_ENABLED' ) ) ? 'cloud' : 'local' ) ,
185- options : ( ) => {
186- const options = [
187- {
188- label : 'Local Dev' ,
189- id : 'local' ,
190- description : 'Edits files on your own machine over SSH' ,
191- } ,
192- ]
193- if ( isTruthy ( getEnv ( 'NEXT_PUBLIC_E2B_ENABLED' ) ) ) {
194- options . unshift (
195- {
196- label : 'Create PR' ,
197- id : 'cloud' ,
198- description : 'Runs in an isolated sandbox, clones your repo, and opens a PR' ,
199- } ,
200- {
201- label : 'Update PR' ,
202- id : 'cloud_branch' ,
203- description : 'Updates an existing branch and creates or updates its pull request' ,
204- } ,
205- {
206- label : 'Review Code' ,
207- id : 'cloud_review' ,
208- description : 'Reviews an existing PR and posts GitHub review comments' ,
209- }
210- )
211- }
212- return options
213- } ,
192+ options : ( ) =>
193+ PI_MODE_IDS . filter (
194+ ( mode ) =>
195+ isTruthy ( getEnv ( 'NEXT_PUBLIC_E2B_ENABLED' ) ) || ! PI_MODE_DEFINITIONS [ mode ] . requiresE2B
196+ ) . map ( ( mode ) => ( {
197+ id : mode ,
198+ label : PI_MODE_DEFINITIONS [ mode ] . label ,
199+ description : PI_MODE_DEFINITIONS [ mode ] . description ,
200+ } ) ) ,
214201 } ,
215202 {
216203 id : 'task' ,
@@ -524,7 +511,7 @@ export const PiBlock: BlockConfig<PiResponse> = {
524511 type : 'skill-input' ,
525512 defaultValue : [ ] ,
526513 mode : 'advanced' ,
527- condition : AUTHORING_MODES ,
514+ condition : CONTEXTUAL_MODES ,
528515 } ,
529516 {
530517 id : 'thinkingLevel' ,
@@ -554,7 +541,7 @@ export const PiBlock: BlockConfig<PiResponse> = {
554541 { label : 'Sliding window (tokens)' , id : 'sliding_window_tokens' } ,
555542 ] ,
556543 mode : 'advanced' ,
557- condition : AUTHORING_MODES ,
544+ condition : CONTEXTUAL_MODES ,
558545 } ,
559546 {
560547 id : 'conversationId' ,
@@ -564,12 +551,12 @@ export const PiBlock: BlockConfig<PiResponse> = {
564551 mode : 'advanced' ,
565552 required : {
566553 field : 'mode' ,
567- value : [ 'cloud' , 'cloud_branch' , 'local' ] ,
554+ value : [ ... PI_CONTEXTUAL_MODES ] ,
568555 and : { field : 'memoryType' , value : MEMORY_TYPES } ,
569556 } ,
570557 condition : {
571558 field : 'mode' ,
572- value : [ 'cloud' , 'cloud_branch' , 'local' ] ,
559+ value : [ ... PI_CONTEXTUAL_MODES ] ,
573560 and : { field : 'memoryType' , value : MEMORY_TYPES } ,
574561 } ,
575562 dependsOn : [ 'memoryType' ] ,
@@ -582,7 +569,7 @@ export const PiBlock: BlockConfig<PiResponse> = {
582569 mode : 'advanced' ,
583570 condition : {
584571 field : 'mode' ,
585- value : [ 'cloud' , 'cloud_branch' , 'local' ] ,
572+ value : [ ... PI_CONTEXTUAL_MODES ] ,
586573 and : { field : 'memoryType' , value : [ 'sliding_window' ] } ,
587574 } ,
588575 dependsOn : [ 'memoryType' ] ,
@@ -595,7 +582,7 @@ export const PiBlock: BlockConfig<PiResponse> = {
595582 mode : 'advanced' ,
596583 condition : {
597584 field : 'mode' ,
598- value : [ 'cloud' , 'cloud_branch' , 'local' ] ,
585+ value : [ ... PI_CONTEXTUAL_MODES ] ,
599586 and : { field : 'memoryType' , value : [ 'sliding_window_tokens' ] } ,
600587 } ,
601588 dependsOn : [ 'memoryType' ] ,
0 commit comments