mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:20:43 +00:00
context-engine: make factory ctx parameter required
This commit is contained in:
committed by
Josh Lehman
parent
6ceb1b5981
commit
c88f7fe452
@@ -360,7 +360,7 @@ describe("Engine contract tests", () => {
|
||||
const resolved = getContextEngineFactory("mock");
|
||||
expect(resolved).toBe(factory);
|
||||
|
||||
const engine = await resolved!();
|
||||
const engine = await resolved!({});
|
||||
expect(engine).toBeInstanceOf(MockContextEngine);
|
||||
expect(engine.info.id).toBe("mock");
|
||||
});
|
||||
@@ -706,7 +706,7 @@ describe("Factory context passing", () => {
|
||||
const engineId = `factory-ctx-${Date.now().toString(36)}`;
|
||||
let receivedCtx: ContextEngineFactoryContext | undefined;
|
||||
|
||||
const factory: ContextEngineFactory = (ctx?: ContextEngineFactoryContext) => {
|
||||
const factory: ContextEngineFactory = (ctx: ContextEngineFactoryContext) => {
|
||||
receivedCtx = ctx;
|
||||
return {
|
||||
info: { id: engineId, name: "Ctx Engine" },
|
||||
@@ -771,7 +771,7 @@ describe("Factory context passing", () => {
|
||||
// Override the default "legacy" engine to intercept the no-config path
|
||||
registerContextEngineForOwner(
|
||||
"legacy",
|
||||
(ctx?: ContextEngineFactoryContext) => {
|
||||
(ctx: ContextEngineFactoryContext) => {
|
||||
receivedCtx = ctx;
|
||||
return {
|
||||
info: { id: "legacy", name: "NoConfig Engine", version: "1" },
|
||||
|
||||
@@ -19,12 +19,13 @@ export type ContextEngineFactoryContext = {
|
||||
* A factory that creates a ContextEngine instance.
|
||||
* Supports async creation for engines that need DB connections etc.
|
||||
*
|
||||
* Factories may accept an optional {@link ContextEngineFactoryContext} parameter
|
||||
* for runtime context. No-arg factories remain supported for backward compatibility
|
||||
* since the parameter is optional.
|
||||
* The factory receives a {@link ContextEngineFactoryContext} with runtime
|
||||
* environment context (config, paths). Existing no-arg factories remain
|
||||
* backward compatible because TypeScript permits assigning functions with
|
||||
* fewer parameters to wider signatures.
|
||||
*/
|
||||
export type ContextEngineFactory = (
|
||||
ctx?: ContextEngineFactoryContext,
|
||||
ctx: ContextEngineFactoryContext,
|
||||
) => ContextEngine | Promise<ContextEngine>;
|
||||
export type ContextEngineRegistrationResult = { ok: true } | { ok: false; existingOwner: string };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user