Skip to content

Commit 6bb3442

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
chore(pi): organize mode implementations
1 parent e1f2bf8 commit 6bb3442

49 files changed

Lines changed: 349 additions & 211 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/sim/blocks/blocks/pi.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vi.mock('@/lib/core/config/env', async (importOriginal) => {
1818

1919
import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility'
2020
import { PiBlock } from '@/blocks/blocks/pi'
21-
import { PI_SEARCH_PROVIDERS } from '@/executor/handlers/pi/keys'
21+
import { PI_SEARCH_PROVIDERS } from '@/executor/handlers/pi/core/keys'
2222

2323
const searchProviderField = PiBlock.subBlocks.find((subBlock) => subBlock.id === 'searchProvider')
2424
const searchApiKeyField = PiBlock.subBlocks.find((subBlock) => subBlock.id === 'searchApiKey')

apps/sim/blocks/blocks/pi.ts

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { PiIcon } from '@/components/icons'
22
import { 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'
311
import type { BlockConfig } from '@/blocks/types'
412
import { AuthMode, IntegrationType } from '@/blocks/types'
513
import {
@@ -8,7 +16,6 @@ import {
816
getProviderCredentialSubBlocks,
917
PROVIDER_CREDENTIAL_INPUTS,
1018
} from '@/blocks/utils'
11-
import { isPiByokOnlyMode } from '@/providers/pi-providers'
1219
import type { ToolResponse } from '@/tools/types'
1320

1421
interface 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
}
6471
const CLOUD_AUTHORING: { field: 'mode'; value: Array<'cloud' | 'cloud_branch'> } = {
6572
field: 'mode',
66-
value: ['cloud', 'cloud_branch'],
73+
value: [...PI_CLOUD_AUTHORING_MODES],
6774
}
6875
const BABYSIT_ENABLED_VALUES: Array<true | 'true'> = [true, 'true']
6976
const 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
}
7885
function getCloudWithoutBabysitCondition(values?: Record<string, unknown>): {
@@ -106,12 +113,12 @@ function getCloudBranchWithoutBabysitCondition(values?: Record<string, unknown>)
106113
}
107114
}
108115
const 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
}
116123
const 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'],

apps/sim/executor/handlers/pi/cloud-backend.test.ts renamed to apps/sim/executor/handlers/pi/cloud/authoring/backend.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ vi.mock('@/lib/execution/remote-sandbox/pi-lifetime', () => ({
3030
// lifetime is the ceiling because there is nothing shorter to narrow to.
3131
resolvePiRunLifetimeMs: () => 40 * 60 * 1000,
3232
}))
33-
vi.mock('@/executor/handlers/pi/babysit-backend', () => ({
33+
vi.mock('@/executor/handlers/pi/cloud/babysit', () => ({
3434
runBabysitPi: mockRunBabysit,
3535
}))
3636
vi.mock('@/tools', () => ({ executeTool: mockExecuteTool }))
37-
vi.mock('@/executor/handlers/pi/keys', () => ({
37+
vi.mock('@/executor/handlers/pi/core/keys', () => ({
3838
providerApiKeyEnvVar: mockProviderEnvVar,
3939
mapThinkingLevel: () => 'medium',
4040
}))
41-
vi.mock('@/executor/handlers/pi/context', () => ({ buildPiPrompt: () => 'PROMPT' }))
41+
vi.mock('@/executor/handlers/pi/core/context', () => ({ buildPiPrompt: () => 'PROMPT' }))
4242

4343
import { createTimeoutAbortController } from '@/lib/core/execution-limits'
44-
import type { PiCloudBranchRunParams, PiCloudRunParams } from '@/executor/handlers/pi/backend'
45-
import { runCloudBranchPi, runCloudPi } from '@/executor/handlers/pi/cloud-backend'
44+
import { runCloudBranchPi, runCloudPi } from '@/executor/handlers/pi/cloud/authoring/backend'
45+
import type { PiCloudBranchRunParams, PiCloudRunParams } from '@/executor/handlers/pi/core/backend'
4646

4747
function baseParams(overrides: Partial<PiCloudRunParams> = {}): PiCloudRunParams {
4848
return {

apps/sim/executor/handlers/pi/cloud-backend.ts renamed to apps/sim/executor/handlers/pi/cloud/authoring/backend.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ import {
2828
resolvePiRunLifetimeMs,
2929
resolvePiSandboxLifetimeMs,
3030
} from '@/lib/execution/remote-sandbox/pi-lifetime'
31-
import { runBabysitPi } from '@/executor/handlers/pi/babysit-backend'
32-
import type {
33-
PiBackendRun,
34-
PiCloudBranchRunParams,
35-
PiCloudRunParams,
36-
PiRunContext,
37-
PiRunResult,
38-
} from '@/executor/handlers/pi/backend'
31+
import { runBabysitPi } from '@/executor/handlers/pi/cloud/babysit'
32+
import {
33+
type BranchPullRequest,
34+
fetchOpenPrForBranch,
35+
findOpenPrForBranch,
36+
setPullRequestDraftState,
37+
} from '@/executor/handlers/pi/cloud/github-pr'
3938
import {
4039
buildPiScript,
4140
CLONE_TIMEOUT_MS,
@@ -54,26 +53,27 @@ import {
5453
raceAbort,
5554
resolvePiTimeoutMs,
5655
scrubGitSecrets,
57-
} from '@/executor/handlers/pi/cloud-shared'
58-
import { buildPiPrompt } from '@/executor/handlers/pi/context'
56+
} from '@/executor/handlers/pi/cloud/shared'
57+
import type {
58+
PiBackendRun,
59+
PiCloudBranchRunParams,
60+
PiCloudRunParams,
61+
PiRunContext,
62+
PiRunResult,
63+
} from '@/executor/handlers/pi/core/backend'
64+
import { buildPiPrompt } from '@/executor/handlers/pi/core/context'
5965
import {
6066
applyPiEvent,
6167
createPiTotals,
6268
type PiRunTotals,
6369
parseJsonLine,
64-
} from '@/executor/handlers/pi/events'
65-
import {
66-
type BranchPullRequest,
67-
fetchOpenPrForBranch,
68-
findOpenPrForBranch,
69-
setPullRequestDraftState,
70-
} from '@/executor/handlers/pi/github-pr'
71-
import { mapThinkingLevel, providerApiKeyEnvVar } from '@/executor/handlers/pi/keys'
70+
} from '@/executor/handlers/pi/core/events'
71+
import { mapThinkingLevel, providerApiKeyEnvVar } from '@/executor/handlers/pi/core/keys'
7272
import {
7373
createScrubbedPiError,
7474
scrubPiEvent,
7575
scrubPiSecrets,
76-
} from '@/executor/handlers/pi/redaction'
76+
} from '@/executor/handlers/pi/core/redaction'
7777
import {
7878
PI_SEARCH_API_KEY_ENV_VAR,
7979
PI_SEARCH_EXTENSION_PATH,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { runCloudBranchPi, runCloudPi } from '@/executor/handlers/pi/cloud/authoring/backend'

apps/sim/executor/handlers/pi/babysit-backend.test.ts renamed to apps/sim/executor/handlers/pi/cloud/babysit/backend.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ vi.mock('@/lib/execution/remote-sandbox/pi-lifetime', async (importOriginal) =>
4646
resolvePiSandboxLifetimeMs: mockResolvePiSandboxLifetime,
4747
}
4848
})
49-
vi.mock('@/executor/handlers/pi/babysit-github', async (importOriginal) => {
50-
const original = await importOriginal<typeof import('@/executor/handlers/pi/babysit-github')>()
49+
vi.mock('@/executor/handlers/pi/cloud/babysit/github', async (importOriginal) => {
50+
const original =
51+
await importOriginal<typeof import('@/executor/handlers/pi/cloud/babysit/github')>()
5152
return {
5253
...original,
5354
fetchBabysitSnapshot: mockFetchSnapshot,
@@ -64,10 +65,10 @@ import { createTimeoutAbortController, getMaxExecutionTimeout } from '@/lib/core
6465
import {
6566
resolveBabysitExecutionBudgetMs,
6667
runBabysitPiWithOptions,
67-
} from '@/executor/handlers/pi/babysit-backend'
68-
import { BABYSIT_ROUND_PATH } from '@/executor/handlers/pi/babysit-round'
69-
import type { PiBabysitContinuationParams } from '@/executor/handlers/pi/backend'
70-
import { DIFF_PATH } from '@/executor/handlers/pi/cloud-shared'
68+
} from '@/executor/handlers/pi/cloud/babysit/backend'
69+
import { BABYSIT_ROUND_PATH } from '@/executor/handlers/pi/cloud/babysit/round'
70+
import { DIFF_PATH } from '@/executor/handlers/pi/cloud/shared'
71+
import type { PiBabysitContinuationParams } from '@/executor/handlers/pi/core/backend'
7172

7273
afterAll(resetEnvMock)
7374

apps/sim/executor/handlers/pi/babysit-backend.ts renamed to apps/sim/executor/handlers/pi/cloud/babysit/backend.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ import {
2929
fetchBabysitThreads,
3030
replyAndResolveBabysitThreads,
3131
requestBabysitReview,
32-
} from '@/executor/handlers/pi/babysit-github'
32+
} from '@/executor/handlers/pi/cloud/babysit/github'
3333
import {
3434
BABYSIT_ROUND_PATH,
3535
MAX_ROUND_FILE_BYTES,
3636
MAX_THREADS_PER_ROUND,
3737
parseBabysitRound,
38-
} from '@/executor/handlers/pi/babysit-round'
39-
import type {
40-
PiBabysitContinuationParams,
41-
PiRunContext,
42-
PiRunResult,
43-
} from '@/executor/handlers/pi/backend'
38+
} from '@/executor/handlers/pi/cloud/babysit/round'
4439
import {
4540
buildPiScript,
4641
CLONE_TIMEOUT_MS,
@@ -58,20 +53,25 @@ import {
5853
raceAbort,
5954
resolvePiTimeoutMs,
6055
scrubGitSecrets,
61-
} from '@/executor/handlers/pi/cloud-shared'
62-
import { buildPiPrompt } from '@/executor/handlers/pi/context'
56+
} from '@/executor/handlers/pi/cloud/shared'
57+
import type {
58+
PiBabysitContinuationParams,
59+
PiRunContext,
60+
PiRunResult,
61+
} from '@/executor/handlers/pi/core/backend'
62+
import { buildPiPrompt } from '@/executor/handlers/pi/core/context'
6363
import {
6464
applyPiEvent,
6565
createPiTotals,
6666
type PiRunTotals,
6767
parseJsonLine,
68-
} from '@/executor/handlers/pi/events'
69-
import { mapThinkingLevel, providerApiKeyEnvVar } from '@/executor/handlers/pi/keys'
68+
} from '@/executor/handlers/pi/core/events'
69+
import { mapThinkingLevel, providerApiKeyEnvVar } from '@/executor/handlers/pi/core/keys'
7070
import {
7171
createScrubbedPiError,
7272
scrubPiEvent,
7373
scrubPiSecrets,
74-
} from '@/executor/handlers/pi/redaction'
74+
} from '@/executor/handlers/pi/core/redaction'
7575
import {
7676
PI_SEARCH_API_KEY_ENV_VAR,
7777
PI_SEARCH_EXTENSION_PATH,

apps/sim/executor/handlers/pi/babysit-github.test.ts renamed to apps/sim/executor/handlers/pi/cloud/babysit/github.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
fetchBabysitSnapshot,
1313
fetchBabysitThreads,
1414
replyAndResolveBabysitThreads,
15-
} from '@/executor/handlers/pi/babysit-github'
15+
} from '@/executor/handlers/pi/cloud/babysit/github'
1616

1717
const HEAD_SHA = 'a'.repeat(40)
1818
const BASE_SHA = 'b'.repeat(40)

apps/sim/executor/handlers/pi/babysit-github.ts renamed to apps/sim/executor/handlers/pi/cloud/babysit/github.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getErrorMessage } from '@sim/utils/errors'
22
import { truncate } from '@sim/utils/string'
3-
import type { BabysitRoundDecision } from '@/executor/handlers/pi/babysit-round'
3+
import type { BabysitRoundDecision } from '@/executor/handlers/pi/cloud/babysit/round'
44
import {
55
fetchPrSnapshot,
66
type PullRequestCoordinates,
77
type PullRequestSnapshot,
88
validateRepositoryCoordinates,
9-
} from '@/executor/handlers/pi/github-pr'
10-
import { scrubPiSecrets } from '@/executor/handlers/pi/redaction'
9+
} from '@/executor/handlers/pi/cloud/github-pr'
10+
import { scrubPiSecrets } from '@/executor/handlers/pi/core/redaction'
1111
import { executeTool } from '@/tools'
1212
import {
1313
isRecord,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { runBabysitPi } from '@/executor/handlers/pi/cloud/babysit/backend'

0 commit comments

Comments
 (0)