Files
windmill/frontend/src/lib/components/flows/aiAgentModules.ts
T
GuilhemandClaude Opus 5 449b1a6933 fix: ground the chat's AI agent provider in the workspace's models (#10774)
* fix: ground the chat's AI agent provider in the workspace's models

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: never reject an AI agent model the catalog could not confirm

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test: benchmark AI agent provider grounding in ai_evals

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: only reject an AI agent model an exhaustive listing rules out

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: keep instance-level AI settings out of the workspace provider catalog

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: keep untrusted model ids out of the chat's context

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* refactor: carry completeness on the model listing itself

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: correct two comments left behind by the catalog rework

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: bound the model listing and verify the default against it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: honour a workspace default a filtered listing names

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: recognise a workspace default past the prompt's model cap

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: keep an aliasing provider's unlisted model ids permissive

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 10:42:02 +02:00

34 lines
1.3 KiB
TypeScript

import type { FlowModule } from '$lib/gen'
/** Visit every AI agent module of a module tree, including agents nested inside agent tools.
* Takes `unknown` so it also runs on model-produced JSON that has not been schema-checked yet.
*
* Lives in its own leaf module (types only) so validation code can traverse a flow without
* pulling in the editor-side agent tool helpers. */
export function forEachAiAgentModule(
modules: unknown,
cb: (mod: FlowModule, value: Record<string, any>) => void
): void {
const visit = (mods: unknown) => {
if (!Array.isArray(mods)) return
for (const mod of mods) {
const v = (mod as FlowModule | undefined)?.value as Record<string, any> | undefined
if (!v) continue
if (v.type === 'aiagent') {
cb(mod as FlowModule, v)
visit(v.tools)
} else if (v.type === 'forloopflow' || v.type === 'whileloopflow') {
visit(v.modules)
} else if (v.type === 'branchone' || v.type === 'branchall') {
if (v.type === 'branchone') visit(v.default)
// Model-produced JSON reaches this before any schema check, so a `branches` that
// is not an array must fall through to the schema error, not throw here.
if (Array.isArray(v.branches)) {
for (const b of v.branches) visit(b?.modules)
}
}
}
}
visit(modules)
}