···11+import { AtpAgent, ComAtprotoLabelDefs } from "@atproto/api";
22+33+/**
44+ * Declare the labels this labeler will apply. Necessary for users to be able to configure what they see.
55+ * @param agent The agent logged into the labeler account.
66+ * @param labelDefinitions The label definitions to declare. You can learn about the definition format [here](https://docs.bsky.app/docs/advanced-guides/moderation#custom-label-values).
77+ */
88+export async function declareLabeler(
99+ agent: AtpAgent,
1010+ labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>,
1111+): Promise<void>;
1212+/**
1313+ * Declare the labels this labeler will apply. Necessary for users to be able to configure what they see.
1414+ * @param credentials The credentials of the labeler account.
1515+ * @param labelDefinitions The label definitions to declare. You can learn about the definition format [here](https://docs.bsky.app/docs/advanced-guides/moderation#custom-label-values).
1616+ */
1717+export async function declareLabeler(
1818+ credentials: { pds?: string; identifier: string; password: string },
1919+ labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>,
2020+): Promise<void>;
2121+export async function declareLabeler(
2222+ agentOrCredentials: AtpAgent | { pds?: string; identifier: string; password: string },
2323+ labelDefinitions: Array<ComAtprotoLabelDefs.LabelValueDefinition>,
2424+) {
2525+ const agent = agentOrCredentials instanceof AtpAgent
2626+ ? agentOrCredentials
2727+ : new AtpAgent({ service: agentOrCredentials.pds || "https://bsky.social" });
2828+ if (!agent.hasSession) {
2929+ if (!(agentOrCredentials instanceof AtpAgent)) {
3030+ await agent.login(agentOrCredentials);
3131+ } else {
3232+ throw new Error("A password must be provided to log in to the labeler account.");
3333+ }
3434+ }
3535+3636+ const labelValues = labelDefinitions.map(({ identifier }) => identifier);
3737+ await agent.app.bsky.labeler.service.create({ repo: agent.did }, {
3838+ policies: { labelValues, labelValueDefinitions: labelDefinitions },
3939+ createdAt: new Date().toUTCString(),
4040+ });
4141+}