Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import {useCallback, useEffect, useMemo, useRef, useState} from "react"

import type {SchemaProperty} from "@agenta/entities/shared"
import {workflowBuildKitEnabledAtomFamily} from "@agenta/entities/workflow"
import {ConfigAccordionSection} from "@agenta/ui/components/presentational"
import {useDrillInUI} from "@agenta/ui/drill-in"
import {cn} from "@agenta/ui/styles"
Expand All @@ -38,7 +39,7 @@ import {
Wrench,
} from "@phosphor-icons/react"
import {Button, Tabs, Tag, Tooltip, Typography} from "antd"
import {useAtomValue} from "jotai"
import {useAtomValue, useStore} from "jotai"

import {useOptionalDrillIn} from "../components/MoleculeDrillInContext"

Expand Down Expand Up @@ -122,17 +123,30 @@ export function AgentTemplateControl({
// is restored on Cancel, giving the same draft-then-save feel as the item drawers.
const [openSection, setOpenSection] = useState<null | "model-harness" | "advanced">(null)
const sectionSnapshot = useRef<Record<string, unknown> | null>(null)
// Snapshot + restore for the build-kit enabled atom (lives outside config; needs separate tracking).
const store = useStore()
const revisionIdRef = useRef<string | null>(null)
const buildKitEnabledSnapshot = useRef<boolean | null>(null)
const openSectionDrawer = useCallback(
(key: "model-harness" | "advanced") => {
sectionSnapshot.current = value ?? {}
buildKitEnabledSnapshot.current = store.get(
workflowBuildKitEnabledAtomFamily(revisionIdRef.current ?? ""),
)
setOpenSection(key)
},
[value],
[value, store],
)
const cancelSection = useCallback(() => {
if (sectionSnapshot.current) onChange(sectionSnapshot.current)
if (buildKitEnabledSnapshot.current !== null) {
store.set(
workflowBuildKitEnabledAtomFamily(revisionIdRef.current ?? ""),
buildKitEnabledSnapshot.current,
)
}
setOpenSection(null)
}, [onChange])
}, [onChange, store])
const saveSection = useCallback(() => setOpenSection(null), [])

// Layout (accordion / tabs / cards) is a global persisted preference; the panel only reads it.
Expand All @@ -153,6 +167,7 @@ export function AgentTemplateControl({
// useModelHarness) and bound-trigger scoping both key off it.
const drillIn = useOptionalDrillIn<unknown>()
const revisionId = drillIn?.entityId ?? null
revisionIdRef.current = revisionId
// Triggers bound to this agent (for the section count badge). The section body and the header
// add-dropdown derive scoping from the same hook.
const {count: triggerCount} = useAgentTriggers(revisionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function useBuildKit({
const [buildKitEnabled, setBuildKitEnabled] = useAtom(
useMemo(() => workflowBuildKitEnabledAtomFamily(revisionId ?? ""), [revisionId]),
)
const [buildKitExpanded, setBuildKitExpanded] = useState(true)
const [buildKitExpanded, setBuildKitExpanded] = useState(false)

const overlayTools = useMemo(
() => (Array.isArray(agentTemplateOverlay?.tools) ? agentTemplateOverlay.tools : []),
Expand Down Expand Up @@ -193,6 +193,7 @@ export function useBuildKit({
<div className="rounded border border-solid border-[var(--ag-c-EAEFF5,#eaeff5)] bg-[#fcfcfa]">
<button
type="button"
aria-expanded={buildKitExpanded}
onClick={() => setBuildKitExpanded((open) => !open)}
className="flex w-full cursor-pointer items-center gap-2 border-0 bg-transparent px-3 py-2.5 text-left"
>
Expand Down
Loading
Loading