export * from './types.js';
import { createAgentHandle } from '../listeners.js';
const counters = new Map();
/**
 * Generate the next default agent name for a harness `base` (e.g. `task-bot`,
 * `task-bot-2`, …), or return `explicit` unchanged when provided. Shared by all
 * harness factories so names stay unique.
 */
export function nextHarnessName(base, explicit) {
    if (explicit)
        return explicit;
    const n = (counters.get(base) ?? 0) + 1;
    counters.set(base, n);
    return n === 1 ? base : `${base}-${n}`;
}
function explicitName(input) {
    return input && typeof input === 'object' ? input.name : undefined;
}
/**
 * Wrap a {@link HarnessConfig} in a factory with `create`/`new`. The returned
 * factory produces registerable {@link SessionHarnessAgent}s while keeping the
 * adapter reachable via `config` for runtimes that bring the session online.
 */
export function defineHarness(config) {
    const build = (input) => {
        const name = nextHarnessName(config.name, explicitName(input));
        const handle = createAgentHandle({ id: `harness:${config.name}:${name}`, name });
        return { ...handle, kind: 'session', input: input, config };
    };
    return {
        name: config.name,
        config,
        create: async (input) => build(input),
        new: (input) => build(input),
    };
}
export function normalizeAgentIdentity(input) {
    const handle = input.handle ?? formatAgentHandle(input.name);
    return {
        id: input.id ?? handle,
        name: input.name,
        handle,
        ...(input.displayName ? { displayName: input.displayName } : {}),
        ...(input.description ? { description: input.description } : {}),
        ...(input.metadata ? { metadata: input.metadata } : {}),
    };
}
export function formatAgentHandle(name) {
    const trimmed = name.trim();
    if (!trimmed)
        return '@agent';
    return trimmed.startsWith('@') ? trimmed : `@${trimmed.replace(/\s+/g, '-')}`;
}
//# sourceMappingURL=index.js.map