import { i as OpenClawConfig } from "./types.openclaw-lNZZW1-s.js";
import { d as SecretInput } from "./types.secrets-C15Z_eLX.js";
import { a as fetchWithSsrFGuard } from "./fetch-guard-BKvfwdRa.js";
import { l as shouldUseEnvHttpProxyForUrl } from "./proxy-env-CRHrWZla.js";
import { m as EmbeddingInput, t as MemoryChunk } from "./internal-BdqTjAl0.js";

//#region packages/memory-host-sdk/src/host/embeddings.types.d.ts
type EmbeddingProvider = {
  id: string;
  model: string;
  maxInputTokens?: number;
  embedQuery: (text: string, options?: EmbeddingProviderCallOptions) => Promise<number[]>;
  embedBatch: (texts: string[], options?: EmbeddingProviderCallOptions) => Promise<number[][]>;
  embedBatchInputs?: (inputs: EmbeddingInput[], options?: EmbeddingProviderCallOptions) => Promise<number[][]>;
  close?: () => Promise<void> | void;
};
type EmbeddingProviderCallOptions = {
  signal?: AbortSignal;
};
type EmbeddingProviderRequest = string;
type EmbeddingProviderFallback = string;
type GeminiTaskType = "RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION";
type EmbeddingProviderOptions = {
  config: OpenClawConfig;
  agentDir?: string;
  provider?: EmbeddingProviderRequest;
  remote?: {
    baseUrl?: string;
    apiKey?: SecretInput;
    headers?: Record<string, string>;
  };
  model: string;
  inputType?: string;
  queryInputType?: string;
  documentInputType?: string;
  fallback?: EmbeddingProviderFallback;
  local?: {
    modelPath?: string;
    modelCacheDir?: string;
    /**
     * Context size passed to node-llama-cpp `createEmbeddingContext`.
     * Default: 4096, chosen to cover typical memory-search chunks (128–512 tokens)
     * while keeping non-weight VRAM bounded.
     * Set `"auto"` to let node-llama-cpp use the model's trained maximum — not
     * recommended for 8B+ models (e.g. Qwen3-Embedding-8B: up to 40 960 tokens → ~32 GB VRAM).
     */
    contextSize?: number | "auto";
  }; /** Provider-specific output vector dimensions for supported embedding families. */
  outputDimensionality?: number; /** Gemini: override the default task type sent with embedding requests. */
  taskType?: GeminiTaskType;
};
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings.d.ts
type LocalEmbeddingProviderRuntimeOptions = {
  workerScriptPath?: string;
  nodeLlamaCppImportUrl?: string;
};
declare function createLocalEmbeddingProvider(options: EmbeddingProviderOptions, runtimeOptions?: LocalEmbeddingProviderRuntimeOptions): Promise<EmbeddingProvider>;
//#endregion
//#region packages/memory-host-sdk/src/host/batch-error-utils.d.ts
/** Minimal batch output line shape that can carry provider error messages. */
type BatchOutputErrorLike = {
  error?: {
    message?: string;
  };
  response?: {
    body?: string | {
      error?: {
        message?: string;
      };
    };
  };
};
/** Return the first useful error message from batch output lines. */
declare function extractBatchErrorMessage(lines: BatchOutputErrorLike[]): string | undefined;
/** Format a failed error-file read without hiding the underlying read problem. */
declare function formatUnavailableBatchError(err: unknown): string | undefined;
//#endregion
//#region packages/memory-host-sdk/src/host/retry-utils.d.ts
/** Retry timing configuration with optional jitter. */
type RetryConfig = {
  attempts?: number;
  minDelayMs?: number;
  maxDelayMs?: number;
  jitter?: number;
};
/** Retry callback payload. */
type RetryInfo = {
  attempt: number;
  maxAttempts: number;
  delayMs: number;
  err: unknown;
  label?: string;
};
/** Retry options for retryAsync. */
type RetryOptions = RetryConfig & {
  label?: string;
  shouldRetry?: (err: unknown, attempt: number) => boolean;
  retryAfterMs?: (err: unknown) => number | undefined;
  onRetry?: (info: RetryInfo) => void;
};
/** Run an async operation with exponential backoff retry handling. */
declare function retryAsync<T>(fn: () => Promise<T>, attemptsOrOptions?: number | RetryOptions, initialDelayMs?: number): Promise<T>;
//#endregion
//#region packages/memory-host-sdk/src/host/ssrf-policy.d.ts
/** Host/network allowlist policy forwarded to the runtime SSRF guard. */
type SsrFPolicy = {
  allowPrivateNetwork?: boolean;
  dangerouslyAllowPrivateNetwork?: boolean;
  allowRfc2544BenchmarkRange?: boolean;
  allowIpv6UniqueLocalRange?: boolean;
  allowedHostnames?: string[];
  hostnameAllowlist?: string[];
};
//#endregion
//#region packages/memory-host-sdk/src/host/batch-http.d.ts
/** POST JSON and retry provider 429/5xx failures with bounded backoff. */
declare function postJsonWithRetry<T>(params: {
  url: string;
  headers: Record<string, string>;
  ssrfPolicy?: SsrFPolicy;
  fetchImpl?: typeof fetch;
  retryImpl?: typeof retryAsync;
  body: unknown;
  errorPrefix: string;
}): Promise<T>;
//#endregion
//#region packages/memory-host-sdk/src/host/batch-output.d.ts
/** Minimal OpenAI-compatible embedding batch output line. */
type EmbeddingBatchOutputLine = {
  custom_id?: string;
  error?: {
    message?: string;
  };
  response?: {
    status_code?: number;
    body?: {
      data?: Array<{
        embedding?: number[];
      }>;
      error?: {
        message?: string;
      };
    } | string;
  };
};
/** Apply one output line, collecting errors and successful embeddings by custom id. */
declare function applyEmbeddingBatchOutputLine(params: {
  line: EmbeddingBatchOutputLine;
  remaining: Set<string>;
  errors: string[];
  byCustomId: Map<string, number[]>;
}): void;
//#endregion
//#region packages/memory-host-sdk/src/host/batch-provider-common.d.ts
/** Provider output line after an embedding batch file is read. */
type ProviderBatchOutputLine = EmbeddingBatchOutputLine;
/** OpenAI-compatible endpoint used inside embedding batch request lines. */
declare const EMBEDDING_BATCH_ENDPOINT = "/v1/embeddings";
//#endregion
//#region packages/memory-host-sdk/src/host/batch-runner.d.ts
/** Execution controls for provider embedding batch submissions and polling. */
type EmbeddingBatchExecutionParams = {
  wait: boolean;
  pollIntervalMs: number;
  timeoutMs: number;
  concurrency: number;
  debug?: (message: string, data?: Record<string, unknown>) => void;
};
type EmbeddingBatchGroupRunArgs<TRequest> = {
  group: TRequest[];
  groupIndex: number;
  groups: number;
  byCustomId: Map<string, number[]>;
  pollIntervalMs: number;
  timeoutMs: number;
};
type EmbeddingBatchSplitArgs<TRequest> = {
  error: unknown;
  group: TRequest[];
  parts: TRequest[][];
  groupIndex: number;
  groups: number;
  depth: number;
};
/** Run request groups with bounded concurrency and return embeddings by custom id. */
declare function runEmbeddingBatchGroups<TRequest>(params: {
  requests: TRequest[];
  maxRequests: number;
  maxJsonlBytes?: number;
  wait: EmbeddingBatchExecutionParams["wait"];
  pollIntervalMs: EmbeddingBatchExecutionParams["pollIntervalMs"];
  timeoutMs: EmbeddingBatchExecutionParams["timeoutMs"];
  concurrency: EmbeddingBatchExecutionParams["concurrency"];
  debugLabel: string;
  debug?: EmbeddingBatchExecutionParams["debug"];
  shouldSplitGroupOnError?: (error: unknown, group: TRequest[]) => boolean;
  onSplitGroup?: (args: EmbeddingBatchSplitArgs<TRequest>) => void;
  runGroup: (args: EmbeddingBatchGroupRunArgs<TRequest>) => Promise<void>;
}): Promise<Map<string, number[]>>;
/** Build normalized batch-group options for provider-specific runners. */
declare function buildEmbeddingBatchGroupOptions<TRequest>(params: {
  requests: TRequest[];
} & EmbeddingBatchExecutionParams, options: {
  maxRequests: number;
  maxJsonlBytes?: number;
  debugLabel: string;
}): {
  requests: TRequest[];
  maxRequests: number;
  maxJsonlBytes: number | undefined;
  wait: boolean;
  pollIntervalMs: number;
  timeoutMs: number;
  concurrency: number;
  debug: ((message: string, data?: Record<string, unknown>) => void) | undefined;
  debugLabel: string;
};
//#endregion
//#region packages/memory-host-sdk/src/host/batch-status.d.ts
/** Minimal provider batch status used for completion and terminal-failure checks. */
type BatchStatusLike = {
  id?: string;
  status?: string;
  output_file_id?: string | null;
  error_file_id?: string | null;
};
/** File ids returned once a batch has completed. */
type BatchCompletionResult = {
  outputFileId: string;
  errorFileId?: string;
};
/** Convert a completed provider status payload into output/error file ids. */
declare function resolveBatchCompletionFromStatus(params: {
  provider: string;
  batchId: string;
  status: BatchStatusLike;
}): BatchCompletionResult;
/** Throw when a provider reports a terminal failure, including error-file detail if available. */
declare function throwIfBatchTerminalFailure(params: {
  provider: string;
  status: BatchStatusLike;
  readError: (errorFileId: string) => Promise<string | undefined>;
}): Promise<void>;
/** Resolve the completed batch files, optionally waiting according to caller policy. */
declare function resolveCompletedBatchResult(params: {
  provider: string;
  status: BatchStatusLike;
  wait: boolean;
  waitForBatch: () => Promise<BatchCompletionResult>;
}): Promise<BatchCompletionResult>;
//#endregion
//#region packages/memory-host-sdk/src/host/batch-utils.d.ts
/** Minimal HTTP client config needed by batch providers. */
type BatchHttpClientConfig = {
  baseUrl?: string;
  headers?: Record<string, string>;
  ssrfPolicy?: SsrFPolicy;
  fetchImpl?: typeof fetch;
};
/** Normalize batch API base URLs by removing one trailing slash. */
declare function normalizeBatchBaseUrl(client: BatchHttpClientConfig): string;
/** Build request headers, preserving caller auth and controlling JSON/form content type. */
declare function buildBatchHeaders(client: Pick<BatchHttpClientConfig, "headers">, params: {
  json: boolean;
}): Record<string, string>;
//#endregion
//#region packages/memory-host-sdk/src/host/batch-upload.d.ts
/** Upload embedding batch requests and return the provider file id. */
declare function uploadBatchJsonlFile(params: {
  client: BatchHttpClientConfig;
  requests: unknown[];
  errorPrefix: string;
  maxResponseBytes?: number;
}): Promise<string>;
//#endregion
//#region packages/memory-host-sdk/src/host/embedding-chunk-limits.d.ts
/**
 * Split text-only chunks to the provider's effective input limit.
 *
 * Structured multimodal chunks are preserved because only the provider can decide how to count
 * non-text parts.
 */
declare function enforceEmbeddingMaxInputTokens(provider: EmbeddingProvider, chunks: MemoryChunk[], hardMaxInputTokens?: number): MemoryChunk[];
//#endregion
//#region packages/memory-host-sdk/src/host/embedding-provider-adapter-utils.d.ts
/** Detect missing API key errors from provider auth resolution. */
declare function isMissingEmbeddingApiKeyError(err: unknown): boolean;
/** Return stable cache headers after removing provider-specific secret headers. */
declare function sanitizeEmbeddingCacheHeaders(headers: Record<string, string>, excludedHeaderNames: string[]): Array<[string, string]>;
/** Convert custom-id keyed batch embeddings back to request-index order. */
declare function mapBatchEmbeddingsByIndex(byCustomId: Map<string, number[]>, count: number): number[][];
//#endregion
//#region packages/memory-host-sdk/src/host/embedding-vectors.d.ts
/** Replace invalid coordinates and L2-normalize non-empty vectors. */
declare function sanitizeAndNormalizeEmbedding(vec: number[]): number[];
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings-debug.d.ts
/** Write embedding debug metadata when OPENCLAW_DEBUG_MEMORY_EMBEDDINGS is enabled. */
declare function debugEmbeddingsLog(message: string, meta?: Record<string, unknown>): void;
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings-model-normalize.d.ts
/** Trim a configured model id, fall back when empty, and strip known prefixes. */
declare function normalizeEmbeddingModelWithPrefixes(params: {
  model: string;
  defaultModel: string;
  prefixes: string[];
}): string;
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings-remote-client.d.ts
/** Provider id used for remote embedding auth and config lookup. */
type RemoteEmbeddingProviderId = string;
/** Resolve base URL, bearer headers, header overrides, and SSRF policy for remote embeddings. */
declare function resolveRemoteEmbeddingBearerClient(params: {
  provider: RemoteEmbeddingProviderId;
  options: EmbeddingProviderOptions;
  defaultBaseUrl: string;
}): Promise<{
  baseUrl: string;
  headers: Record<string, string>;
  ssrfPolicy?: SsrFPolicy;
}>;
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings-remote-provider.d.ts
/** HTTP client details required by a remote embedding provider. */
type RemoteEmbeddingClient = {
  baseUrl: string;
  headers: Record<string, string>;
  ssrfPolicy?: SsrFPolicy;
  fetchImpl?: typeof fetch;
  model: string;
};
/** Create an EmbeddingProvider backed by a remote embeddings endpoint. */
declare function createRemoteEmbeddingProvider(params: {
  id: string;
  client: RemoteEmbeddingClient;
  errorPrefix: string;
  maxInputTokens?: number;
}): EmbeddingProvider;
/** Resolve a normalized remote embedding client from provider config and model options. */
declare function resolveRemoteEmbeddingClient(params: {
  provider: RemoteEmbeddingProviderId;
  options: EmbeddingProviderOptions;
  defaultBaseUrl: string;
  normalizeModel: (model: string) => string;
}): Promise<RemoteEmbeddingClient>;
//#endregion
//#region packages/memory-host-sdk/src/host/embeddings-remote-fetch.d.ts
/** POST an embedding request and return validated vectors in provider response order. */
declare function fetchRemoteEmbeddingVectors(params: {
  url: string;
  headers: Record<string, string>;
  ssrfPolicy?: SsrFPolicy;
  fetchImpl?: typeof fetch;
  signal?: AbortSignal;
  body: unknown;
  errorPrefix: string;
}): Promise<number[][]>;
//#endregion
//#region packages/memory-host-sdk/src/host/embedding-input-limits.d.ts
declare function estimateUtf8Bytes(text: string): number;
declare function estimateStructuredEmbeddingInputBytes(input: EmbeddingInput): number;
//#endregion
//#region packages/memory-host-sdk/src/host/remote-http.d.ts
/** Build an SSRF allow policy from a configured remote base URL. */
declare const buildRemoteBaseUrlPolicy: (baseUrl: string) => SsrFPolicy | undefined;
/** Execute a remote HTTP request under SSRF guard and always release the response handle. */
declare function withRemoteHttpResponse<T>(params: {
  url: string;
  init?: RequestInit;
  signal?: AbortSignal;
  ssrfPolicy?: SsrFPolicy;
  fetchImpl?: typeof fetch;
  fetchWithSsrFGuardImpl?: typeof fetchWithSsrFGuard;
  shouldUseEnvHttpProxyForUrlImpl?: typeof shouldUseEnvHttpProxyForUrl;
  auditContext?: string;
  onResponse: (response: Response) => Promise<T>;
}): Promise<T>;
//#endregion
//#region src/plugin-sdk/memory-core-host-engine-embeddings.d.ts
/** Provider batch status payload shared by memory embedding batch helpers. */
type EmbeddingBatchStatus = {
  id?: string;
  status?: string;
  output_file_id?: string | null;
  error_file_id?: string | null;
};
//#endregion
export { EMBEDDING_BATCH_ENDPOINT as A, BatchCompletionResult as C, EmbeddingBatchExecutionParams as D, throwIfBatchTerminalFailure as E, formatUnavailableBatchError as F, createLocalEmbeddingProvider as I, applyEmbeddingBatchOutputLine as M, postJsonWithRetry as N, buildEmbeddingBatchGroupOptions as O, extractBatchErrorMessage as P, normalizeBatchBaseUrl as S, resolveCompletedBatchResult as T, sanitizeEmbeddingCacheHeaders as _, estimateUtf8Bytes as a, BatchHttpClientConfig as b, createRemoteEmbeddingProvider as c, resolveRemoteEmbeddingBearerClient as d, normalizeEmbeddingModelWithPrefixes as f, mapBatchEmbeddingsByIndex as g, isMissingEmbeddingApiKeyError as h, estimateStructuredEmbeddingInputBytes as i, ProviderBatchOutputLine as j, runEmbeddingBatchGroups as k, resolveRemoteEmbeddingClient as l, sanitizeAndNormalizeEmbedding as m, buildRemoteBaseUrlPolicy as n, fetchRemoteEmbeddingVectors as o, debugEmbeddingsLog as p, withRemoteHttpResponse as r, RemoteEmbeddingClient as s, EmbeddingBatchStatus as t, RemoteEmbeddingProviderId as u, enforceEmbeddingMaxInputTokens as v, resolveBatchCompletionFromStatus as w, buildBatchHeaders as x, uploadBatchJsonlFile as y };