/**
 * Plugin LLM access types for the CLEO trust-gating layer.
 *
 * Defines the context, completion signature, and error types that the plugin
 * LLM facade exposes to plugin consumers. Phase 5 (T9313) adds full
 * sandboxing: permissions descriptor, filesystem ACL, and per-plugin
 * in-memory token-bucket rate limiting.
 *
 * @module llm/plugin-llm
 * @task T9305
 * @task T9313
 * @epic T9261 T-LLM-CRED-CENTRALIZATION
 * @see ADR-072 §6 plugin facade
 */
// ---------------------------------------------------------------------------
// Error types
// ---------------------------------------------------------------------------
/**
 * Thrown when a plugin requests a model or provider not in its allow-list.
 *
 * Consumers can `instanceof PluginModelGateError` to distinguish trust-gating
 * failures from general executor errors.
 */
export class PluginModelGateError extends Error {
    /** Plugin that triggered the gate. */
    pluginId;
    /** The model or provider identifier that was denied. */
    denied;
    /** Which axis triggered the gate: model or provider. */
    axis;
    /**
     * @param pluginId - Plugin whose request was denied.
     * @param denied - The specific value that was not in the allow-list.
     * @param axis - Whether the denial was on the `model` or `provider` axis.
     */
    constructor(pluginId, denied, axis) {
        super(`Plugin "${pluginId}" is not permitted to use ${axis} "${denied}". ` +
            `Check the plugin manifest's allowed${axis === 'model' ? 'Models' : 'Providers'} list.`);
        this.name = 'PluginModelGateError';
        this.pluginId = pluginId;
        this.denied = denied;
        this.axis = axis;
    }
}
/**
 * Wraps an underlying executor error after credential patterns have been
 * redacted from its message and stack.
 *
 * The original cause is preserved in `Error.cause` for internal logging but
 * the message and stack exposed to the plugin are sanitised.
 */
export class PluginLlmError extends Error {
    /** Plugin on whose behalf the call was made. */
    pluginId;
    /**
     * @param pluginId - Plugin on whose behalf the failing call was made.
     * @param redactedMessage - Credential-scrubbed error message.
     * @param cause - Original unscrubbed error (for internal diagnostics).
     */
    constructor(pluginId, redactedMessage, cause) {
        super(redactedMessage, { cause });
        this.name = 'PluginLlmError';
        this.pluginId = pluginId;
    }
}
/**
 * Thrown when a plugin call is denied by the permissions descriptor.
 *
 * Covers violations of `maxTokens`, `maxCostUsd`, `allowedRoles`, and other
 * call-site constraints declared in {@link PluginPermissionDescriptor}.
 *
 * Error code: `E_PLUGIN_DENIED`
 */
export class PluginDeniedError extends Error {
    /** Plugin whose request was denied. */
    pluginId;
    /** Human-readable reason for the denial. */
    reason;
    /** Machine-readable error code. */
    code = 'E_PLUGIN_DENIED';
    /**
     * @param pluginId - Plugin whose request was denied.
     * @param reason - Reason the request was denied.
     */
    constructor(pluginId, reason) {
        super(`Plugin "${pluginId}" was denied: ${reason}`);
        this.name = 'PluginDeniedError';
        this.pluginId = pluginId;
        this.reason = reason;
    }
}
/**
 * Thrown when a plugin has exhausted its in-memory token-bucket rate limit.
 *
 * The `retryAfterMs` field indicates how many milliseconds until the bucket
 * refills enough for one token. Callers should surface this as a
 * `Retry-After` header or equivalent.
 *
 * Error code: `E_PLUGIN_RATE_LIMITED`
 */
export class PluginRateLimitedError extends Error {
    /** Plugin that triggered the rate limit. */
    pluginId;
    /** Milliseconds until the bucket refills enough for one token. */
    retryAfterMs;
    /** Machine-readable error code. */
    code = 'E_PLUGIN_RATE_LIMITED';
    /**
     * @param pluginId - Plugin that was rate-limited.
     * @param retryAfterMs - Milliseconds until capacity is available.
     */
    constructor(pluginId, retryAfterMs) {
        super(`Plugin "${pluginId}" is rate-limited. Retry after ${retryAfterMs}ms.`);
        this.name = 'PluginRateLimitedError';
        this.pluginId = pluginId;
        this.retryAfterMs = retryAfterMs;
    }
}
//# sourceMappingURL=plugin-llm.js.map