





























@@ -52,7 +52,8 @@ import {
5252isConfiguredAgent,
5353updateAgentConfigEntry,
5454} from "./agents-config-mutations.js";
55-import type { GatewayRequestContext, GatewayRequestHandlers, RespondFn } from "./types.js";
55+import { loadOptionalServerMethodModelCatalog } from "./optional-model-catalog.js";
56+import type { GatewayRequestHandlers, RespondFn } from "./types.js";
56575758const BOOTSTRAP_FILE_NAMES = [
5859DEFAULT_AGENTS_FILENAME,
@@ -72,41 +73,6 @@ const agentsHandlerDeps = {
7273 isWorkspaceSetupCompleted,
7374};
747575-let loggedSlowAgentsListCatalog = false;
76-77-const AGENTS_LIST_MODEL_CATALOG_TIMEOUT_MS = 750;
78-79-async function loadOptionalAgentsListModelCatalog(
80-context: GatewayRequestContext,
81-): Promise<Awaited<ReturnType<GatewayRequestContext["loadGatewayModelCatalog"]>> | undefined> {
82-let timeout: NodeJS.Timeout | undefined;
83-const timedOut = Symbol("agents-list-model-catalog-timeout");
84-const timeoutPromise = new Promise<typeof timedOut>((resolve) => {
85-timeout = setTimeout(() => resolve(timedOut), AGENTS_LIST_MODEL_CATALOG_TIMEOUT_MS);
86-timeout.unref?.();
87-});
88-try {
89-const result = await Promise.race([
90-context.loadGatewayModelCatalog().catch(() => undefined),
91-timeoutPromise,
92-]);
93-if (result === timedOut) {
94-if (!loggedSlowAgentsListCatalog) {
95-loggedSlowAgentsListCatalog = true;
96-context.logGateway.debug(
97-`agents.list continuing without model catalog after ${AGENTS_LIST_MODEL_CATALOG_TIMEOUT_MS}ms`,
98-);
99-}
100-return undefined;
101-}
102-return Array.isArray(result) ? result : undefined;
103-} finally {
104-if (timeout) {
105-clearTimeout(timeout);
106-}
107-}
108-}
109-11076export const testing = {
11177setDepsForTests(
11278overrides: Partial<{
@@ -527,7 +493,9 @@ export const agentsHandlers: GatewayRequestHandlers = {
527493}
528494529495const cfg = context.getRuntimeConfig();
530-const modelCatalog = await loadOptionalAgentsListModelCatalog(context);
496+const modelCatalog = await loadOptionalServerMethodModelCatalog(context, "agents.list", {
497+logOnceKey: "agents.list",
498+});
531499const result = listAgentsForGateway(cfg, modelCatalog);
532500respond(true, result, undefined);
533501},
@@ -783,7 +751,11 @@ export const agentsHandlers: GatewayRequestHandlers = {
783751},
784752"agents.files.list": async ({ params, respond, context }) => {
785753if (!validateAgentsFilesListParams(params)) {
786-respondInvalidMethodParams(respond, "agents.files.list", validateAgentsFilesListParams.errors);
754+respondInvalidMethodParams(
755+respond,
756+"agents.files.list",
757+validateAgentsFilesListParams.errors,
758+);
787759return;
788760}
789761const cfg = context.getRuntimeConfig();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。