import "./tool-display-DMBmPBI-.js";
import "./paths-WcYpcMAY.js";
import "./auth-profiles-CaNK0cUT.js";
import { C as parseAgentSessionKey, n as DEFAULT_AGENT_ID, u as normalizeAgentId } from "./session-key-Fto5gqqw.js";
import "./exec-CmvuUufz.js";
import { r as resolveAgentConfig } from "./agent-scope-E2aR3Ci_.js";
import "./github-copilot-token-CKOQDjEZ.js";
import "./emitter-BKo8D7Oj.js";
import "./sqlite-CVrhPija.js";
import "./reliability-BnL75OlZ.js";
import "./frontmatter-C3D7gE4Z.js";
import "./skills-UwTwDeDw.js";
import "./manifest-registry-AgGLF4V7.js";
import "./validation-B00oOkJ3.js";
import { o as loadConfig } from "./config-CoCeK5B2.js";
import "./client-DtQEs2_8.js";
import "./call-CkgY6Bq7.js";
import "./message-channel-DKXbq8GH.js";
import "./sessions-CFJLtXRH.js";
import "./accounts-CNwod9BY.js";
import "./accounts-C3i8BBiA.js";
import "./normalize-CRf-uoB2.js";
import "./bindings-B1hNZin3.js";
import "./logging-BiuZwq5D.js";
import "./plugins-DMpYx7kb.js";
import "./image-ops-D0pBQqKh.js";
import "./pi-embedded-helpers-D-q9ylFX.js";
import "./sandbox-C79rEJ_w.js";
import "./chrome-BTLLz_O2.js";
import "./tailscale-V4nwZFBO.js";
import "./auth-Beo6eR0R.js";
import "./server-context-T5wFkzWi.js";
import "./routes-Ch0tqbTH.js";
import "./redact-2qrQ_uJt.js";
import "./errors-BlUw40-o.js";
import "./paths-Cb76_eC_.js";
import "./ssrf-BEPhIfOk.js";
import "./store-Bz34pm8z.js";
import "./ports-BsKQWWi9.js";
import "./trash-Cn3CsF86.js";
import "./dock-BvRrtCWj.js";
import "./accounts-CdYdWklO.js";
import "./paths-CDTtU20P.js";
import "./tool-images-B4eVOjD0.js";
import "./thinking-C03RqJxq.js";
import { a as jsonResult } from "./common-CxpUJZLb.js";
import { f as resolveInternalSessionKey, p as resolveMainSessionAlias } from "./sessions-helpers-NrlH9x7w.js";
import "./pi-embedded-utils-BCSBp2bL.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 };