fix(vectordrive): silence optional dependency warning
This commit is contained in:
parent
22f22181db
commit
626813b616
2 changed files with 40 additions and 11 deletions
|
|
@ -8,8 +8,8 @@
|
|||
import type { ExtensionAPI } from "@singularity-forge/pi-coding-agent";
|
||||
import { VectordriveManager } from "./manager.js";
|
||||
import { registerVectordriveInfoTool } from "./tool-info.js";
|
||||
import { registerVectordriveStoreTool } from "./tool-store.js";
|
||||
import { registerVectordriveSearchTool } from "./tool-search.js";
|
||||
import { registerVectordriveStoreTool } from "./tool-store.js";
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
registerVectordriveInfoTool(pi);
|
||||
|
|
@ -17,16 +17,9 @@ export default function (pi: ExtensionAPI) {
|
|||
registerVectordriveSearchTool(pi);
|
||||
|
||||
// Pre-warm the connection on session start
|
||||
pi.on("session_start", async (_event, ctx) => {
|
||||
pi.on("session_start", async () => {
|
||||
const manager = VectordriveManager.getInstance();
|
||||
const status = await manager.getStatus();
|
||||
|
||||
if (ctx.hasUI && status.backend === "none" && status.error) {
|
||||
ctx.ui.notify(
|
||||
`VectorDrive unavailable: ${status.error}`,
|
||||
"warning",
|
||||
);
|
||||
}
|
||||
await manager.getStatus();
|
||||
});
|
||||
|
||||
pi.on("session_shutdown", async () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { VectordriveManager, textToVector } from "../manager.js";
|
||||
import extension from "../index.js";
|
||||
import { textToVector, VectordriveManager } from "../manager.js";
|
||||
|
||||
describe("VectordriveManager", () => {
|
||||
it("should return singleton instance", () => {
|
||||
|
|
@ -17,6 +18,41 @@ describe("VectordriveManager", () => {
|
|||
expect(status.backend).toBe("none");
|
||||
expect(status.error).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should not warn on session start when optional vectordrive package is absent", async () => {
|
||||
type SessionStartHandler = (
|
||||
event: unknown,
|
||||
ctx: {
|
||||
hasUI: boolean;
|
||||
ui: { notify: (message: string, level: string) => void };
|
||||
},
|
||||
) => Promise<void>;
|
||||
const handlers = new Map<string, SessionStartHandler>();
|
||||
const notifications: Array<{ message: string; level: string }> = [];
|
||||
const pi = {
|
||||
registerTool: () => {},
|
||||
on: (event: string, handler: SessionStartHandler) =>
|
||||
handlers.set(event, handler),
|
||||
};
|
||||
|
||||
const manager = VectordriveManager.getInstance();
|
||||
await manager.close();
|
||||
extension(pi as any);
|
||||
|
||||
await handlers.get("session_start")?.(
|
||||
{},
|
||||
{
|
||||
hasUI: true,
|
||||
ui: {
|
||||
notify: (message: string, level: string) => {
|
||||
notifications.push({ message, level });
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(notifications).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("textToVector", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue