Laimiao agent v2 service: agent orchestration, sessions, billing, gateway client, skills catalog, auth, config, plus tests.
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { SessionStore } from "../src/sessions/store.js";
|
|
import { silentLogger, tempRoot } from "./helpers.js";
|
|
|
|
function makeStore(root: string) {
|
|
return new SessionStore(join(root, "sessions.json"), join(root, "messages"), silentLogger);
|
|
}
|
|
|
|
describe("SessionStore", () => {
|
|
it("creates, lists, and owns sessions", async () => {
|
|
const store = makeStore(tempRoot());
|
|
const session = await store.create({ uid: "1", team_id: "t1" }, { title: "hello" });
|
|
expect((await store.get(session.session_id))?.title).toBe("hello");
|
|
expect((await store.getOwned({ uid: "1", team_id: "t1" }, session.session_id))?.session_id).toBe(
|
|
session.session_id,
|
|
);
|
|
expect(await store.getOwned({ uid: "2", team_id: "t1" }, session.session_id)).toBeUndefined();
|
|
expect((await store.list({ uid: "1" })).total).toBe(1);
|
|
expect((await store.list({ uid: "2" })).total).toBe(0);
|
|
});
|
|
|
|
it("appends messages, updates metadata, and auto-titles from the first user message", async () => {
|
|
const store = makeStore(tempRoot());
|
|
const session = await store.create({ uid: "1", team_id: "t1" });
|
|
await store.append(session.session_id, {
|
|
role: "user",
|
|
mode: "agent",
|
|
content: "帮我做一张云南海报",
|
|
media: [],
|
|
status: "ok",
|
|
});
|
|
await store.append(session.session_id, {
|
|
role: "assistant",
|
|
mode: "image",
|
|
content: "已完成",
|
|
media: [{ type: "image", url: "https://img/1.png" }],
|
|
status: "ok",
|
|
});
|
|
|
|
const meta = await store.get(session.session_id);
|
|
expect(meta?.message_count).toBe(2);
|
|
expect(meta?.last_mode).toBe("image");
|
|
expect(meta?.title).toBe("帮我做一张云南海报");
|
|
const messages = await store.messages(session.session_id);
|
|
expect(messages).toHaveLength(2);
|
|
expect(messages[1]?.media[0]?.url).toBe("https://img/1.png");
|
|
});
|
|
|
|
it("persists the index and paginates", async () => {
|
|
const root = tempRoot();
|
|
const store = makeStore(root);
|
|
for (let index = 0; index < 3; index += 1) {
|
|
await store.create({ uid: "1", team_id: "t1" }, { title: `s${index}` });
|
|
}
|
|
const reloaded = makeStore(root);
|
|
expect((await reloaded.list({ uid: "1" })).total).toBe(3);
|
|
expect((await reloaded.list({ uid: "1", limit: 2 })).sessions).toHaveLength(2);
|
|
expect((await reloaded.list({ uid: "1", limit: 2, offset: 2 })).sessions).toHaveLength(1);
|
|
});
|
|
});
|