import "./pi-embedded-utils-BmQgIEul.js";
import "./subsystem-Ci61Iebe.js";
import "./paths-aMBPuCJR.js";
import "./auth-profiles-CfyCILIe.js";
import "./env-3oW17BWM.js";
import { b as parseAgentSessionKey, n as DEFAULT_AGENT_ID, u as normalizeAgentId } from "./session-key-j5Y_js6r.js";
import "./exec-B5OgjUV4.js";
import { n as resolveAgentConfig } from "./agent-scope-CCFV2dzL.js";
import "./github-copilot-token-CgLcR-3z.js";
import "./reliability-B6TVU4OW.js";
import "./sqlite-CbyDDiup.js";
import "./accounts-TaYXhwSR.js";
import "./dock-BRgbOpqS.js";
import "./normalize-Dz9m5w2g.js";
import "./bindings-jC2ZutIF.js";
import "./plugins-6aUfx6Yt.js";
import "./message-channel-BCPYwYUJ.js";
import "./image-ops-DfgorOBP.js";
import "./pi-embedded-helpers-DmbNPuyh.js";
import { n as loadConfig } from "./config-CaBTSkpu.js";
import "./manifest-registry-BPLS_vpk.js";
import "./chrome-CDWGRT0_.js";
import "./server-context-CU0HZM8q.js";
import "./skills-CEb7zc7i.js";
import "./redact-BXcZFg1V.js";
import "./errors-CGLTQpIl.js";
import "./ssrf-Clw7QAxV.js";
import "./sessions-FK8zYE33.js";
import "./paths-a4Li8t1f.js";
import "./tool-images-D39TNWEi.js";
import "./thinking-B4KYQMkY.js";
import { a as jsonResult } from "./common-BkBiFnII.js";
import "./call-CHvC3jba.js";
import { f as resolveInternalSessionKey, p as resolveMainSessionAlias } from "./sessions-helpers-BkUTlqiP.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 };