Files
windmill/ai_evals/modes/global.ts
GuilhemandClaude Opus 5.5 9536cfdab1 feat: ask for secrets and connect services in the AI chat through a secure card (#12575)
* feat: ask for secrets in the AI chat through a secure input card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: overwrite a secret only once the card shows its path as taken

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: settle a stopped secret request, keep multiline secrets, link the saving workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: sanitize the secret card's help link, report a save that lands after stop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: let the chat run the secret save, so it alone settles the card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: let a secret save land before opening a past chat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: write a late secret save before a chat switch, recheck for a turn after waiting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: connect a service from one secret card that saves the secrets and creates the resource

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a turn sent during new chat, set the type of a replaced resource, honour replace for its variables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: connect postgres from a pasted connection string on the secret card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: scope replace to the path the AI asked for, save only what the connection string says

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: test a connection from the secret card through a shared connection-test module, show provider steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: render the secret card's provider steps as markdown

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: test saved storage resources from their stored value, key retry ownership by kind

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say how each saved-resource check reads its secrets, reattach saveSecretRequest's comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: serve request_secret to MCP clients through a signed link to a secure input page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: open the secure input page on its own, outside the app's navigation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: ask only what shapes the secret card, label its fields per the form guidelines, load the user on the secure input page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: save the secure input card's secrets and resource as drafts the AI offers to deploy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: name the resource and encrypted variables the secure input card saves, copy the reply to the assistant

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: confirm before the secret card replaces your drafts, keep a replaced secret's expiry, record and report saves landing after stop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 22:49:22 +01:00

146 lines
4.8 KiB
TypeScript

import { readFile, stat } from "node:fs/promises";
import { basename } from "node:path";
import { loadAppFixtureForEval } from "../adapters/frontend/core/app/appFixtureLoader";
import {
runGlobalEval,
type GlobalLiveEditorDraftFixture,
type GlobalUserFixture,
} from "../adapters/frontend/core/global/globalEvalRunner";
import type { SeededArtifact } from "../adapters/frontend/core/global/evalArtifactStore";
import type { EvalPreviewTabFixture } from "../adapters/frontend/core/global/evalPreviewTabs";
import type { BenchmarkWorkspaceRunnables } from "../adapters/frontend/mockBackend";
import type { FrontendEvalModelConfig } from "../core/models";
import type {
BenchmarkArtifactFile,
GlobalValidationSpec,
ModeRunner,
} from "../core/types";
import { validateGlobalState, type GlobalDraftState } from "../core/validators";
import type { WindmillBackendSettings } from "../core/windmillBackendSettings";
import { getFrontendApiKey } from "./frontendCommon";
export interface GlobalInitialFixture {
workspace?: BenchmarkWorkspaceRunnables;
liveEditorDrafts?: GlobalLiveEditorDraftFixture[];
user?: GlobalUserFixture;
artifacts?: SeededArtifact[];
previewTabs?: EvalPreviewTabFixture[];
}
export function createGlobalModeRunner(
modelConfig: FrontendEvalModelConfig,
backendSettings: WindmillBackendSettings,
): ModeRunner<GlobalInitialFixture, GlobalDraftState, GlobalDraftState> {
return {
mode: "global",
// Each attempt holds a workspace of its own, and CE allows two besides `admins`; a third
// attempt would wait for a slot, and the wait would count toward its duration.
concurrency: 2,
judgeThreshold: 80,
async loadInitial(path) {
return path ? await loadGlobalInitialFixture(path) : undefined;
},
async loadExpected(path) {
return path ? await loadGlobalExpectedFixture(path) : undefined;
},
async run(prompt, initial, context) {
const result = await runGlobalEval(
prompt,
getFrontendApiKey(modelConfig.provider),
{
workspaceFixtures: initial?.workspace,
liveEditorDrafts: initial?.liveEditorDrafts,
user: initial?.user,
artifacts: initial?.artifacts,
previewTabs: initial?.previewTabs,
sessionChat: context.evalCase?.runtime?.sessionChat,
planMode: context.evalCase?.runtime?.planMode,
profile: context.evalCase?.runtime?.profile,
pipelineRun: context.executionOnly
? undefined
: (context.evalCase?.validate as GlobalValidationSpec | undefined)?.pipelineRun,
maxIterations: context.evalCase?.runtime?.maxTurns,
userAnswers: context.evalCase?.runtime?.userAnswers,
secretRequests: context.evalCase?.runtime?.secretRequests,
provider: modelConfig.provider,
model: modelConfig.model,
backend: backendSettings,
runContext: context,
},
);
return {
success: result.success,
actual: result.state,
error: result.error,
assistantMessageCount: result.assistantMessageCount,
toolCallCount: result.toolCallCount,
toolsUsed: result.toolsUsed,
toolCallDetails: result.toolCallDetails,
skillsInvoked: [],
assistantText: result.assistantText,
tokenUsage: result.tokenUsage,
finalContextTokens: result.finalContextTokens,
};
},
validate({ evalCase, actual, expected }) {
return validateGlobalState({
actual,
expected,
validate: evalCase.validate as GlobalValidationSpec | undefined,
});
},
buildArtifacts(actual): BenchmarkArtifactFile[] {
return [
{
path: "global-drafts.json",
content: JSON.stringify(actual, null, 2) + "\n",
},
];
},
};
}
async function loadGlobalInitialFixture(
path: string,
): Promise<GlobalInitialFixture> {
if ((await stat(path)).isDirectory()) {
const { initialFrontend, initialBackend, initialDatatables } =
await loadAppFixtureForEval(path);
const name = basename(path);
return {
workspace: {
apps: [
{
path: `f/evals/global/${name}`,
summary: name,
value: {
files: initialFrontend,
runnables: initialBackend,
data: initialDatatables,
},
},
],
},
liveEditorDrafts: [],
};
}
const parsed = JSON.parse(
await readFile(path, "utf8"),
) as GlobalInitialFixture;
return {
workspace: parsed.workspace ?? {},
liveEditorDrafts: parsed.liveEditorDrafts ?? [],
user: parsed.user,
artifacts: parsed.artifacts,
previewTabs: parsed.previewTabs ?? [],
};
}
async function loadGlobalExpectedFixture(
path: string,
): Promise<GlobalDraftState> {
return JSON.parse(await readFile(path, "utf8")) as GlobalDraftState;
}