Przeglądaj źródła

feat(paas): honor managed deployment profile

241880436@seecoder.cn 4 dni temu
rodzic
commit
ba0b1c2e09

+ 19 - 1
packages/app/e2e/paas/fixture.tsx

@@ -298,11 +298,29 @@ const platform: Platform = {
   restart: async () => {},
   notify: async () => {},
 }
+const managed = new URLSearchParams(location.search).has("managed")
 render(
   () => (
     <PlatformProvider value={platform}>
       <AppBaseProviders locale="zh">
-        {new URLSearchParams(location.search).has("panel") ? <PanelFixture /> : <PaasWorkspace standalone />}
+        {new URLSearchParams(location.search).has("panel") ? (
+          <PanelFixture />
+        ) : (
+          <PaasWorkspace
+            standalone
+            deployment={
+              managed
+                ? {
+                    edition: "team",
+                    platformUrl: "https://team.example",
+                    allowCustomPlatform: false,
+                    modelPolicy: "managed",
+                    permissionsDefault: "allow",
+                  }
+                : undefined
+            }
+          />
+        )}
       </AppBaseProviders>
     </PlatformProvider>
   ),

+ 17 - 0
packages/app/e2e/paas/workbench.spec.ts

@@ -380,3 +380,20 @@ test("generated file cards open the right preview, resize and close at the lower
   await page.keyboard.press("Escape")
   await expect(page.locator(".paas-preview")).toHaveCount(0)
 })
+
+test("managed deployment locks the platform address and model fields", async ({ page }) => {
+  await page.goto("/e2e/paas/index.html?managed&ux")
+  const address = page.locator('input[type="url"]')
+  await expect(address).toHaveValue("https://team.example")
+  await expect(address).toHaveAttribute("readonly", "")
+  await expect(page.getByRole("button", { name: "一键连接本机", exact: true })).toHaveCount(0)
+  await page.getByLabel("API Key", { exact: true }).fill("test-only")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await expect(page.locator(".paas-topbar-chat-title")).toBeVisible()
+
+  await page.getByRole("button", { name: "智能体", exact: true }).click()
+  await page.getByRole("button", { name: "编辑 科研助手", exact: true }).click()
+  await expect(page.getByRole("heading", { name: "编辑智能体", exact: true })).toBeVisible()
+  await expect(page.getByText("模型由平台统一提供,不能在客户端修改。", { exact: true })).toBeVisible()
+  await expect(page.getByText("模型提供商", { exact: true })).toHaveCount(0)
+})

+ 10 - 2
packages/app/src/pages/paas/agent-edit.tsx

@@ -90,6 +90,7 @@ export function PaasAgentEdit(props: {
   onSaved: () => Promise<void>
   draft?: AgentEditDraft
   onDraft?: (draft?: AgentEditDraft) => void
+  modelPolicy?: "self-service" | "managed"
 }) {
   const [state, setState] = createStore({
     original: undefined as Record<string, unknown> | undefined,
@@ -345,9 +346,16 @@ export function PaasAgentEdit(props: {
               </div>
             </fieldset>
           </details>
+          <Show when={props.modelPolicy === "managed"}>
+            <p class="paas-notice" role="status">
+              模型由平台统一提供,不能在客户端修改。
+            </p>
+          </Show>
           <For
-            each={configuration.filter((group) =>
-              scientific() ? ["scientific", "model"].includes(group.key) : group.key !== "scientific",
+            each={configuration.filter(
+              (group) =>
+                (group.key !== "model" || props.modelPolicy !== "managed") &&
+                (scientific() ? ["scientific", "model"].includes(group.key) : group.key !== "scientific"),
             )}
           >
             {(group) => (

+ 1 - 0
packages/app/src/pages/paas/deployment.ts

@@ -3,6 +3,7 @@ export type PaasModelPolicy = "self-service" | "managed"
 
 export type PaasDeploymentProfile = {
   edition: PaasEdition
+  platformUrl?: string
   allowCustomPlatform: boolean
   modelPolicy: PaasModelPolicy
   permissionsDefault: "allow" | "deny"

+ 27 - 10
packages/app/src/pages/paas/index.tsx

@@ -14,7 +14,7 @@ import { useTabs } from "@/context/tabs"
 import { paasRecord, paasStatus, paasStatuses, paasText } from "@/paas"
 import { showToast } from "@/utils/toast"
 import { createPaasWorkspace } from "./controller"
-import { personalDeployment } from "./deployment"
+import { personalDeployment, type PaasDeploymentProfile } from "./deployment"
 import {
   clampNavWidth,
   clampPreviewWidth,
@@ -69,11 +69,13 @@ function agentInitial(agent: Record<string, unknown>) {
 export default function PaasWorkspace(
   props: {
     standalone?: boolean
+    deployment?: PaasDeploymentProfile
     onOpenDeveloper?: (directory?: string) => void
     registerMenuCommand?: (handler: ((id: string) => boolean) | undefined) => void
   } = {},
 ) {
   const platform = usePlatform()
+  const deployment = () => props.deployment ?? personalDeployment
   const dialog = useDialog()
   const global = props.standalone ? undefined : useGlobal()
   const server = props.standalone ? undefined : useServer()
@@ -82,7 +84,7 @@ export default function PaasWorkspace(
   const navigate = props.standalone ? undefined : useNavigate()
   const drafts = new Map<string, AgentEditDraft>()
   const workspace = createPaasWorkspace(platform.paas, {
-    permissionsDefault: personalDeployment.permissionsDefault,
+    permissionsDefault: deployment().permissionsDefault,
   })
   const state = workspace.state
   const disabled = () => !!state.busy || !state.connected
@@ -283,6 +285,10 @@ export default function PaasWorkspace(
       () => setUI({ notices: [], chatTask: undefined, management: "" }),
     ),
   )
+  createEffect(() => {
+    const url = deployment().platformUrl
+    if (url && !state.connected) workspace.setState("url", url)
+  })
   createEffect(
     on(
       () => state.page,
@@ -906,7 +912,11 @@ export default function PaasWorkspace(
                   <section class="paas-panel paas-connect paas-connection-page" aria-label="平台连接">
                     <div>
                       <strong>{state.connected ? "连接信息" : "连接你的 AgentPaaS"}</strong>
-                      <p>填写管理员提供的平台地址与访问凭证,即可开始研究。已有本机平台服务可直接一键连接。</p>
+                      <p>
+                        {deployment().allowCustomPlatform
+                          ? "填写管理员提供的平台地址与访问凭证,即可开始研究。已有本机平台服务可直接一键连接。"
+                          : "平台地址已由部署预置,请填写访问凭证后连接。"}
+                      </p>
                       <p class="paas-muted">桌面端不会自动安装平台服务。记住连接后,下次打开可自动进入工作台。</p>
                       <p class="paas-muted">
                         连接成功表示平台目录可访问;执行服务和模型是否可用,可在“资源检查”中进一步确认。
@@ -945,10 +955,14 @@ export default function PaasWorkspace(
                             type="url"
                             required
                             value={state.url}
+                            readOnly={!deployment().allowCustomPlatform}
                             disabled={!!state.busy}
                             onInput={(event) => workspace.setState("url", event.currentTarget.value)}
                             placeholder="https://paas.example.com"
                           />
+                          <Show when={!deployment().allowCustomPlatform}>
+                            <small class="paas-muted">平台地址由部署预置,不能修改。</small>
+                          </Show>
                         </label>
                         <label>
                           API Key
@@ -973,13 +987,15 @@ export default function PaasWorkspace(
                         <button class="paas-primary" type="submit" disabled={!platform.paas || !!state.busy}>
                           连接平台
                         </button>
-                        <button
-                          type="button"
-                          disabled={!platform.paas || !!state.busy}
-                          onClick={() => void workspace.connect(true)}
-                        >
-                          一键连接本机
-                        </button>
+                        <Show when={deployment().allowCustomPlatform}>
+                          <button
+                            type="button"
+                            disabled={!platform.paas || !!state.busy}
+                            onClick={() => void workspace.connect(true)}
+                          >
+                            一键连接本机
+                          </button>
+                        </Show>
                       </form>
                     </Show>
                   </section>
@@ -1179,6 +1195,7 @@ export default function PaasWorkspace(
                 <PaasAgentEdit
                   api={api}
                   agentID={ui.editAgentID}
+                  modelPolicy={deployment().modelPolicy}
                   draft={drafts.get(`${state.scope}:${ui.editAgentID}`)}
                   onDraft={(() => {
                     const key = `${state.scope}:${ui.editAgentID}`