mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 14:48:33 +00:00
Summary: - Merged feat(plugins): add embedding provider contract after ClawSweeper review. Automerge notes: - PR branch already contained follow-up commit before automerge: chore(plugins): refresh embedding provider sdk baseline - PR branch already contained follow-up commit before automerge: docs(plugins): document embedding provider contract - PR branch already contained follow-up commit before automerge: fix(plugins): restore embedding providers after snapshot loads - PR branch already contained follow-up commit before automerge: fix(plugins): resolve embedding providers from manifests - PR branch already contained follow-up commit before automerge: fix(plugin-sdk): keep embedding provider registry mutators internal - PR branch already contained follow-up commit before automerge: chore(plugin-sdk): refresh embedding provider API baseline Validation: - ClawSweeper review passed for head41ebd66ab4. - Required merge gates passed before the squash merge. Prepared head SHA:41ebd66ab4Review: https://github.com/openclaw/openclaw/pull/84947#issuecomment-4514762026 Co-authored-by: Bob <dutifulbob@gmail.com> Co-authored-by: Mariano Belinky <mbelinky@gmail.com> Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com> Approved-by: osolmaz Co-authored-by: osolmaz <2453968+osolmaz@users.noreply.github.com>
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import {
|
|
clearEmbeddingProviders,
|
|
getEmbeddingProvider,
|
|
getRegisteredEmbeddingProvider,
|
|
listEmbeddingProviders,
|
|
listRegisteredEmbeddingProviders,
|
|
registerEmbeddingProvider,
|
|
restoreEmbeddingProviders,
|
|
restoreRegisteredEmbeddingProviders,
|
|
type EmbeddingProviderAdapter,
|
|
} from "./embedding-providers.js";
|
|
|
|
const EMBEDDING_PROVIDERS_KEY = Symbol.for("openclaw.embeddingProviders");
|
|
const INITIAL_REGISTERED_EMBEDDING_PROVIDERS = listRegisteredEmbeddingProviders();
|
|
|
|
function createAdapter(id: string): EmbeddingProviderAdapter {
|
|
return {
|
|
id,
|
|
create: async () => ({ provider: null }),
|
|
};
|
|
}
|
|
|
|
beforeEach(() => {
|
|
clearEmbeddingProviders();
|
|
});
|
|
|
|
afterEach(() => {
|
|
restoreRegisteredEmbeddingProviders(INITIAL_REGISTERED_EMBEDDING_PROVIDERS);
|
|
});
|
|
|
|
describe("embedding provider registry", () => {
|
|
it("registers and lists adapters in insertion order", () => {
|
|
const alpha = createAdapter("alpha");
|
|
const beta = createAdapter("beta");
|
|
|
|
registerEmbeddingProvider(alpha);
|
|
registerEmbeddingProvider(beta);
|
|
|
|
expect(listEmbeddingProviders().map((adapter) => adapter.id)).toEqual(["alpha", "beta"]);
|
|
expect(getEmbeddingProvider("alpha")).toBe(alpha);
|
|
});
|
|
|
|
it("restores adapter snapshots", () => {
|
|
const alpha = createAdapter("alpha");
|
|
const beta = createAdapter("beta");
|
|
registerEmbeddingProvider(alpha);
|
|
|
|
restoreEmbeddingProviders([beta]);
|
|
|
|
expect(getEmbeddingProvider("alpha")).toBeUndefined();
|
|
expect(getEmbeddingProvider("beta")).toBe(beta);
|
|
});
|
|
|
|
it("preserves owner metadata in registered snapshots", () => {
|
|
const adapter = createAdapter("openai-compatible");
|
|
const entry = {
|
|
adapter,
|
|
ownerPluginId: "openai-compatible",
|
|
};
|
|
|
|
restoreRegisteredEmbeddingProviders([entry]);
|
|
|
|
expect(getRegisteredEmbeddingProvider("openai-compatible")).toEqual(entry);
|
|
expect(listRegisteredEmbeddingProviders()).toEqual([entry]);
|
|
});
|
|
|
|
it("stores adapters in a process-global singleton map", () => {
|
|
const adapter = createAdapter("local-protocol");
|
|
registerEmbeddingProvider(adapter, { ownerPluginId: "local-protocol" });
|
|
|
|
const globalRegistry = (globalThis as Record<PropertyKey, unknown>)[
|
|
EMBEDDING_PROVIDERS_KEY
|
|
] as Map<string, { adapter: EmbeddingProviderAdapter; ownerPluginId?: string }>;
|
|
|
|
expect(globalRegistry.get("local-protocol")).toEqual({
|
|
adapter,
|
|
ownerPluginId: "local-protocol",
|
|
});
|
|
});
|
|
});
|