Skip to content

Commit 8e9f8a1

Browse files
rdematosclaude
andcommitted
refactor(managed-agent): remove self-hosted default-row pre-seeding
Pre-seeding the self-hosted block's Session parameters table from the server-only MANAGED_AGENT_SELF_HOSTED_DEFAULTS env var is better served by Sim's workflow blocks. Remove the capability end-to-end: - Delete GET /api/managed-agent-defaults route + test - Drop the MANAGED_AGENT_SELF_HOSTED_DEFAULTS env var - Remove getManagedAgentDefaultsContract + its schemas/types - Remove the fetchManagedAgentSelfHostedDefaults client fetcher - Unwire fetchDefaultRows from the self-hosted block and fix the two stale comments that referenced the removed env var Revert the shared table subblock seeding machinery (table.tsx, sub-block.tsx, blocks/types.ts) to its pre-feature behavior so no other block is affected — table.tsx is now byte-identical to main. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 872953a commit 8e9f8a1

10 files changed

Lines changed: 11 additions & 292 deletions

File tree

apps/sim/app/api/managed-agent-defaults/route.test.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

apps/sim/app/api/managed-agent-defaults/route.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/table/table.tsx

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/c
1515
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
1616
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
1717
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
18-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1918

2019
const logger = createLogger('Table')
2120

@@ -26,21 +25,6 @@ interface TableProps {
2625
isPreview?: boolean
2726
previewValue?: WorkflowTableRow[] | null
2827
disabled?: boolean
29-
/**
30-
* Optional seed rows applied when a fresh block first mounts (store value
31-
* is missing/empty). Each entry's `cells` keys must match `columns` — any
32-
* missing columns fall back to `""`. Existing values are never overwritten.
33-
*/
34-
defaultRows?: Array<{ cells: Record<string, string> }>
35-
/**
36-
* Optional async fetcher for seed rows — used when the block's default
37-
* rows come from a server-side source (e.g. deployer-configured env vars
38-
* read via an API route). Called once on first mount when the store is
39-
* empty. If the fetcher rejects or returns an empty array, falls back to
40-
* `defaultRows`, then to a single empty row. Same overwrite rules as
41-
* `defaultRows`: existing store values are never touched.
42-
*/
43-
fetchDefaultRows?: () => Promise<Array<{ cells: Record<string, string> }>>
4428
}
4529

4630
interface WorkflowTableRow {
@@ -230,8 +214,6 @@ export function Table({
230214
isPreview = false,
231215
previewValue,
232216
disabled = false,
233-
defaultRows,
234-
fetchDefaultRows,
235217
}: TableProps) {
236218
const activeSearchTarget = useActiveSearchTarget()
237219
const params = useParams()
@@ -266,61 +248,18 @@ export function Table({
266248
)
267249

268250
/**
269-
* Initialize the table when the component mounts and the store value has
270-
* never been set. Precedence:
271-
* 1. `fetchDefaultRows` (async) — used when defaults live server-side
272-
* (e.g. deployer env-var read via an API route).
273-
* 2. `defaultRows` (sync) — static seeds declared on the block config.
274-
* 3. Single empty row — the pre-existing behavior.
275-
*
276-
* We only seed when `storeValue` is `null` / `undefined` — a stored
277-
* `[]` means the workflow author intentionally cleared every row and
278-
* must NOT be treated as "unseeded" (would re-seed defaults on every
279-
* remount and clobber the empty state they chose).
251+
* Initialize the table with a default empty row when the component mounts
252+
* and when the current store value is missing or empty.
280253
*/
281254
useEffect(() => {
282-
if (isPreview || disabled) return
283-
if (storeValue !== undefined && storeValue !== null) return
284-
let cancelled = false
285-
const seedWith = (rows: Array<{ cells: Record<string, string> }> | undefined) => {
286-
if (cancelled) return
287-
// Re-read the LATEST value from the subblock store, not the
288-
// closure-captured `storeValue` from render time. Otherwise an
289-
// async `fetchDefaultRows` that resolves after the user has
290-
// already started editing the table would overwrite their
291-
// in-progress rows with the deployer defaults.
292-
const currentValue = useSubBlockStore.getState().getValue(blockId, subBlockId)
293-
if (currentValue !== undefined && currentValue !== null) return
294-
const seedRows: WorkflowTableRow[] =
295-
Array.isArray(rows) && rows.length > 0
296-
? rows.map((row) => ({
297-
id: generateId(),
298-
cells: { ...emptyCellsTemplate, ...(row.cells ?? {}) },
299-
}))
300-
: [{ id: generateId(), cells: { ...emptyCellsTemplate } }]
301-
setStoreValue(seedRows)
302-
}
303-
if (fetchDefaultRows) {
304-
fetchDefaultRows()
305-
.then((rows) => seedWith(rows.length > 0 ? rows : defaultRows))
306-
.catch(() => seedWith(defaultRows))
307-
} else {
308-
seedWith(defaultRows)
309-
}
310-
return () => {
311-
cancelled = true
255+
if (!isPreview && !disabled && (!Array.isArray(storeValue) || storeValue.length === 0)) {
256+
const initialRow: WorkflowTableRow = {
257+
id: generateId(),
258+
cells: { ...emptyCellsTemplate },
259+
}
260+
setStoreValue([initialRow])
312261
}
313-
}, [
314-
isPreview,
315-
disabled,
316-
storeValue,
317-
setStoreValue,
318-
emptyCellsTemplate,
319-
defaultRows,
320-
fetchDefaultRows,
321-
blockId,
322-
subBlockId,
323-
])
262+
}, [isPreview, disabled, storeValue, setStoreValue, emptyCellsTemplate])
324263

325264
// Ensure value is properly typed and initialized
326265
const rows = useMemo(() => {

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/sub-block.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,6 @@ function SubBlockComponent({
749749
isPreview={isPreview}
750750
previewValue={previewValue as any}
751751
disabled={isDisabled}
752-
defaultRows={
753-
Array.isArray(config.defaultValue)
754-
? (config.defaultValue as Array<{ cells: Record<string, string> }>)
755-
: undefined
756-
}
757-
fetchDefaultRows={config.fetchDefaultRows}
758752
/>
759753
)
760754

apps/sim/blocks/blocks/managed_agent_self_hosted.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ vi.mock('@/lib/managed-agents/subblock-options', () => ({
1919
fetchManagedAgentAgentOptions: vi.fn(),
2020
fetchManagedAgentConnectionOptions: vi.fn(),
2121
fetchManagedAgentMemoryStoreOptions: vi.fn(),
22-
fetchManagedAgentSelfHostedDefaults: vi.fn(),
2322
fetchManagedAgentSelfHostedEnvironmentOptions: vi.fn(),
2423
fetchManagedAgentVaultOptions: vi.fn(),
2524
}))

apps/sim/blocks/blocks/managed_agent_self_hosted.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
fetchManagedAgentAgentOptions,
55
fetchManagedAgentConnectionOptions,
66
fetchManagedAgentMemoryStoreOptions,
7-
fetchManagedAgentSelfHostedDefaults,
87
fetchManagedAgentSelfHostedEnvironmentOptions,
98
fetchManagedAgentVaultOptions,
109
} from '@/lib/managed-agents/subblock-options'
@@ -65,8 +64,7 @@ const memorySubBlocks: SubBlockConfig[] = isSelfHostedMemoryEnabled()
6564
* `resources` array. Session metadata (top-level `metadata` field) is
6665
* exposed to the self-hosted agent sandbox as env vars, so this
6766
* block's Session parameters table is where you set the keys your
68-
* deployment reads. The set of supported keys is deployment-specific
69-
* — seed defaults with `NEXT_PUBLIC_MANAGED_AGENT_SELF_HOSTED_DEFAULTS`.
67+
* deployment reads. The set of supported keys is deployment-specific.
7068
*
7169
* The environment picker is filtered to `config.type === 'self_hosted'`.
7270
* Icon renders black-on-white to visually differentiate from the cloud
@@ -161,17 +159,12 @@ export const ManagedAgentSelfHostedBlock: BlockConfig = {
161159
{
162160
// Session metadata forwarded to the self-hosted agent sandbox as
163161
// env vars. The set of supported keys is deployment-specific and
164-
// lives with the deployer, not in this repo. Seed rows come from
165-
// the server-only `MANAGED_AGENT_SELF_HOSTED_DEFAULTS` env var,
166-
// fetched via `/api/managed-agent-defaults` — the values never
167-
// enter the client bundle, so deployers can safely include
168-
// anything their sandbox reads.
162+
// lives with the deployer, not in this repo.
169163
id: 'sessionParameters',
170164
title: 'Session parameters',
171165
type: 'table',
172166
required: false,
173167
columns: ['Key', 'Value'],
174-
fetchDefaultRows: fetchManagedAgentSelfHostedDefaults,
175168
description:
176169
'Key/value pairs forwarded to the self-hosted agent sandbox as environment variables. Supported keys depend on your deployment — consult your deployment docs. Value cells support <block.output> / <var.name> references.',
177170
},

apps/sim/blocks/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,6 @@ export interface SubBlockConfig {
285285
}
286286
})
287287
defaultValue?: string | number | boolean | Record<string, unknown> | Array<unknown>
288-
/**
289-
* Optional async fetcher for a `table` subblock's initial rows — used
290-
* when defaults come from a server-side source (e.g. deployer-configured
291-
* env vars) and must not be inlined into the client bundle. Called once
292-
* on first mount when the store is empty. See `Table.fetchDefaultRows`.
293-
*/
294-
fetchDefaultRows?: () => Promise<Array<{ cells: Record<string, string> }>>
295288
options?:
296289
| {
297290
label: string

apps/sim/lib/api/contracts/managed-agent-connections.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -204,28 +204,3 @@ export const listManagedAgentMemoryStoresContract = defineRouteContract({
204204
}),
205205
},
206206
})
207-
208-
/**
209-
* Server-side default rows the Claude Managed Agents (self-hosted) block
210-
* seeds into its Session parameters table. Deployers configure this via
211-
* the server-only `MANAGED_AGENT_SELF_HOSTED_DEFAULTS` env var (a JSON
212-
* object) so seeded values — which may reference internal keys — never
213-
* touch the client bundle.
214-
*/
215-
export const managedAgentSelfHostedDefaultRowSchema = z.object({
216-
cells: z.record(z.string(), z.string()),
217-
})
218-
export type ManagedAgentSelfHostedDefaultRow = z.output<
219-
typeof managedAgentSelfHostedDefaultRowSchema
220-
>
221-
222-
export const getManagedAgentDefaultsContract = defineRouteContract({
223-
method: 'GET',
224-
path: '/api/managed-agent-defaults',
225-
response: {
226-
mode: 'json',
227-
schema: z.object({
228-
selfHosted: z.array(managedAgentSelfHostedDefaultRowSchema),
229-
}),
230-
},
231-
})

apps/sim/lib/core/config/env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ export const env = createEnv({
149149
OPENAI_API_KEY_3: z.string().min(1).optional(), // Additional OpenAI API key for load balancing
150150
MISTRAL_API_KEY: z.string().min(1).optional(), // Mistral AI API key
151151
MANAGED_AGENT_DEBUG_PAYLOAD: z.string().optional(), // When "1" | "true" | "yes", the Managed Agent workflow-block tool logs the full session-create payload (never includes the api key) so you can inspect memory / vault / metadata routing
152-
MANAGED_AGENT_SELF_HOSTED_DEFAULTS: z.string().optional(), // Server-only JSON object of default session-metadata key/value pairs the Claude Managed Agents (self-hosted) block seeds into fresh workflows. Example: '{"SOURCE_TYPE":"git","SOURCE_REF":"main"}'. Never exposed to the client bundle — read via GET /api/managed-agent-defaults.
153152
ANTHROPIC_API_KEY_1: z.string().min(1).optional(), // Primary Anthropic Claude API key
154153
ANTHROPIC_API_KEY_2: z.string().min(1).optional(), // Additional Anthropic API key for load balancing
155154
ANTHROPIC_API_KEY_3: z.string().min(1).optional(), // Additional Anthropic API key for load balancing

0 commit comments

Comments
 (0)