import "./tool-display-B7qTeoCS.js";
import "./paths-D4_LjrY7.js";
import "./utils-BnlaT0eO.js";
import "./theme-CG-K7m8u.js";
import "./thinking-CKGMvVgd.js";
import "./subsystem-ocBR131w.js";
import "./runtime-CRvfzclG.js";
import { C as parseAgentSessionKey, n as DEFAULT_AGENT_ID, u as normalizeAgentId } from "./session-key-DIUsVZjU.js";
import "./exec-CZr_EJHt.js";
import { r as resolveAgentConfig } from "./agent-scope-CVnlY0oG.js";
import "./model-selection-p6J3l4qF.js";
import "./github-copilot-token-CjSKohyA.js";
import "./emitter-oHo8y9ow.js";
import "./sqlite-wYNyDR1B.js";
import "./reliability-Dl7hbRzF.js";
import "./boolean-DGGu1sGA.js";
import "./env-CvUd308i.js";
import "./validation-p1IK70TM.js";
import { o as loadConfig } from "./config-DJ3A5x_1.js";
import "./manifest-registry-U2EDFVP4.js";
import "./pi-embedded-utils-BraP32ED.js";
import "./redact-DcYCKU6u.js";
import "./pi-embedded-helpers-CLkeTWAT.js";
import "./sandbox-C5rKvtrA.js";
import "./chrome-BQkAVfz8.js";
import "./tailscale-CcUMoDkd.js";
import "./auth-BxKMeEw-.js";
import "./server-context-s_zNpSdX.js";
import "./frontmatter-VFr0KMAQ.js";
import "./skills-CHYyY1lO.js";
import "./routes-CT0DmotX.js";
import "./errors-DbYSuCgv.js";
import "./paths-Ct4sqLyX.js";
import "./ssrf-tneKFjA6.js";
import "./image-ops-C0D77XHD.js";
import "./store-Cdm3Z5cQ.js";
import "./ports-DvLDsgl0.js";
import "./trash-BRBQoy9m.js";
import "./sessions-Ct2d_bGl.js";
import "./message-channel-DSU96OKy.js";
import "./dock-DY0TWaYa.js";
import "./normalize-DgwtBdm-.js";
import "./accounts-BZv5WxME.js";
import "./accounts-DFaskvEN.js";
import "./accounts-T7o73ZSN.js";
import "./bindings-BbaWTQJM.js";
import "./logging-wfRfbMvt.js";
import "./plugins-DYgcd4QJ.js";
import "./paths-DRyRQF9o.js";
import "./tool-images-CRPqucMe.js";
import { a as jsonResult } from "./common-oaZdjdal.js";
import "./client-DNPnFy4E.js";
import "./call-C206Z-zx.js";
import { f as resolveInternalSessionKey, p as resolveMainSessionAlias } from "./sessions-helpers-DYJnJN3U.js";
import { Type } from "@sinclair/typebox";

//#region src/agents/tools/misc/agents-list-tool.ts
const AgentsListToolSchema = Type.Object({});
function createAgentsListTool(opts) {
	return {
		label: "Agents",
		name: "agents_list",
		description: "List agent ids you can target with sessions_spawn (based on allowlists).",
		parameters: AgentsListToolSchema,
		execute: async () => {
			const cfg = loadConfig();
			const { mainKey, alias } = resolveMainSessionAlias(cfg);
			const requesterInternalKey = typeof opts?.agentSessionKey === "string" && opts.agentSessionKey.trim() ? resolveInternalSessionKey({
				key: opts.agentSessionKey,
				alias,
				mainKey
			}) : alias;
			const requesterAgentId = normalizeAgentId(opts?.requesterAgentIdOverride ?? parseAgentSessionKey(requesterInternalKey)?.agentId ?? DEFAULT_AGENT_ID);
			const allowAgents = resolveAgentConfig(cfg, requesterAgentId)?.subagents?.allowAgents ?? [];
			const allowAny = allowAgents.some((value) => value.trim() === "*");
			const allowSet = new Set(allowAgents.filter((value) => value.trim() && value.trim() !== "*").map((value) => normalizeAgentId(value)));
			const configuredAgents = Array.isArray(cfg.agents?.list) ? cfg.agents?.list : [];
			const configuredIds = configuredAgents.map((entry) => normalizeAgentId(entry.id));
			const configuredNameMap = /* @__PURE__ */ new Map();
			for (const entry of configuredAgents) {
				const name = entry?.name?.trim() ?? "";
				if (!name) continue;
				configuredNameMap.set(normalizeAgentId(entry.id), name);
			}
			const allowed = /* @__PURE__ */ new Set();
			allowed.add(requesterAgentId);
			if (allowAny) for (const id of configuredIds) allowed.add(id);
			else for (const id of allowSet) allowed.add(id);
			return jsonResult({
				requester: requesterAgentId,
				allowAny,
				agents: [requesterAgentId, ...Array.from(allowed).filter((id) => id !== requesterAgentId).toSorted((a, b) => a.localeCompare(b))].map((id) => ({
					id,
					name: configuredNameMap.get(id),
					configured: configuredIds.includes(id)
				}))
			});
		}
	};
}

//#endregion
export { createAgentsListTool };