|
|
@@ -1,7 +1,8 @@
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
+import { Effect } from "effect"
|
|
|
import path from "path"
|
|
|
import { Instance } from "../../src/project/instance"
|
|
|
-import { Session } from "../../src/session"
|
|
|
+import { Session as SessionNs } from "../../src/session"
|
|
|
import { MessageV2 } from "../../src/session/message-v2"
|
|
|
import { MessageID, PartID, type SessionID } from "../../src/session/schema"
|
|
|
import { ModelID, ProviderID } from "../../src/provider/schema"
|
|
|
@@ -10,12 +11,32 @@ import { Log } from "../../src/util/log"
|
|
|
const root = path.join(__dirname, "../..")
|
|
|
Log.init({ print: false })
|
|
|
|
|
|
+function run<A, E>(fx: Effect.Effect<A, E, SessionNs.Service>) {
|
|
|
+ return Effect.runPromise(fx.pipe(Effect.provide(SessionNs.defaultLayer)))
|
|
|
+}
|
|
|
+
|
|
|
+const svc = {
|
|
|
+ ...SessionNs,
|
|
|
+ create(input?: SessionNs.CreateInput) {
|
|
|
+ return run(SessionNs.Service.use((svc) => svc.create(input)))
|
|
|
+ },
|
|
|
+ remove(id: SessionID) {
|
|
|
+ return run(SessionNs.Service.use((svc) => svc.remove(id)))
|
|
|
+ },
|
|
|
+ updateMessage<T extends MessageV2.Info>(msg: T) {
|
|
|
+ return run(SessionNs.Service.use((svc) => svc.updateMessage(msg)))
|
|
|
+ },
|
|
|
+ updatePart<T extends MessageV2.Part>(part: T) {
|
|
|
+ return run(SessionNs.Service.use((svc) => svc.updatePart(part)))
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
async function fill(sessionID: SessionID, count: number, time = (i: number) => Date.now() + i) {
|
|
|
const ids = [] as MessageID[]
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
const id = MessageID.ascending()
|
|
|
ids.push(id)
|
|
|
- await Session.updateMessage({
|
|
|
+ await svc.updateMessage({
|
|
|
id,
|
|
|
sessionID,
|
|
|
role: "user",
|
|
|
@@ -25,7 +46,7 @@ async function fill(sessionID: SessionID, count: number, time = (i: number) => D
|
|
|
tools: {},
|
|
|
mode: "",
|
|
|
} as unknown as MessageV2.Info)
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID,
|
|
|
messageID: id,
|
|
|
@@ -38,7 +59,7 @@ async function fill(sessionID: SessionID, count: number, time = (i: number) => D
|
|
|
|
|
|
async function addUser(sessionID: SessionID, text?: string) {
|
|
|
const id = MessageID.ascending()
|
|
|
- await Session.updateMessage({
|
|
|
+ await svc.updateMessage({
|
|
|
id,
|
|
|
sessionID,
|
|
|
role: "user",
|
|
|
@@ -49,7 +70,7 @@ async function addUser(sessionID: SessionID, text?: string) {
|
|
|
mode: "",
|
|
|
} as unknown as MessageV2.Info)
|
|
|
if (text) {
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID,
|
|
|
messageID: id,
|
|
|
@@ -66,7 +87,7 @@ async function addAssistant(
|
|
|
opts?: { summary?: boolean; finish?: string; error?: MessageV2.Assistant["error"] },
|
|
|
) {
|
|
|
const id = MessageID.ascending()
|
|
|
- await Session.updateMessage({
|
|
|
+ await svc.updateMessage({
|
|
|
id,
|
|
|
sessionID,
|
|
|
role: "assistant",
|
|
|
@@ -87,7 +108,7 @@ async function addAssistant(
|
|
|
}
|
|
|
|
|
|
async function addCompactionPart(sessionID: SessionID, messageID: MessageID) {
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID,
|
|
|
messageID,
|
|
|
@@ -101,14 +122,14 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
await fill(session.id, 2)
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 10 })
|
|
|
expect(result).toBeDefined()
|
|
|
expect(result.items).toBeArray()
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -117,7 +138,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 6)
|
|
|
|
|
|
const a = MessageV2.page({ sessionID: session.id, limit: 2 })
|
|
|
@@ -136,7 +157,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(c.more).toBe(false)
|
|
|
expect(c.cursor).toBeUndefined()
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -145,13 +166,13 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 4)
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 4 })
|
|
|
expect(result.items.map((item) => item.info.id)).toEqual(ids)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -160,14 +181,14 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 10 })
|
|
|
expect(result.items).toEqual([])
|
|
|
expect(result.more).toBe(false)
|
|
|
expect(result.cursor).toBeUndefined()
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -186,7 +207,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 3)
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 3 })
|
|
|
@@ -194,7 +215,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(result.more).toBe(false)
|
|
|
expect(result.cursor).toBeUndefined()
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -203,7 +224,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 5)
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 1 })
|
|
|
@@ -211,7 +232,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(result.items[0].info.id).toBe(ids[ids.length - 1])
|
|
|
expect(result.more).toBe(true)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -220,10 +241,10 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: id,
|
|
|
@@ -235,7 +256,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(result.items).toHaveLength(1)
|
|
|
expect(result.items[0].parts).toHaveLength(2)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -244,7 +265,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 4, (i) => 1000.5 + i)
|
|
|
|
|
|
const a = MessageV2.page({ sessionID: session.id, limit: 2 })
|
|
|
@@ -253,7 +274,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(a.items.map((item) => item.info.id)).toEqual(ids.slice(-2))
|
|
|
expect(b.items.map((item) => item.info.id)).toEqual(ids.slice(0, 2))
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -262,7 +283,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 4, () => 1000)
|
|
|
|
|
|
const a = MessageV2.page({ sessionID: session.id, limit: 2 })
|
|
|
@@ -273,7 +294,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(b.items.map((item) => item.info.id)).toEqual(ids.slice(0, 2))
|
|
|
expect(b.more).toBe(false)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -282,8 +303,8 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const a = await Session.create({})
|
|
|
- const b = await Session.create({})
|
|
|
+ const a = await svc.create({})
|
|
|
+ const b = await svc.create({})
|
|
|
await fill(a.id, 3)
|
|
|
await fill(b.id, 2)
|
|
|
|
|
|
@@ -294,8 +315,8 @@ describe("MessageV2.page", () => {
|
|
|
expect(resultA.items.every((item) => item.info.sessionID === a.id)).toBe(true)
|
|
|
expect(resultB.items.every((item) => item.info.sessionID === b.id)).toBe(true)
|
|
|
|
|
|
- await Session.remove(a.id)
|
|
|
- await Session.remove(b.id)
|
|
|
+ await svc.remove(a.id)
|
|
|
+ await svc.remove(b.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -304,7 +325,7 @@ describe("MessageV2.page", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 10)
|
|
|
|
|
|
const result = MessageV2.page({ sessionID: session.id, limit: 100 })
|
|
|
@@ -313,7 +334,7 @@ describe("MessageV2.page", () => {
|
|
|
expect(result.more).toBe(false)
|
|
|
expect(result.cursor).toBeUndefined()
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -324,13 +345,13 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 5)
|
|
|
|
|
|
const items = Array.from(MessageV2.stream(session.id))
|
|
|
expect(items.map((item) => item.info.id)).toEqual(ids.slice().reverse())
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -339,12 +360,12 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
const items = Array.from(MessageV2.stream(session.id))
|
|
|
expect(items).toHaveLength(0)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -353,14 +374,14 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 1)
|
|
|
|
|
|
const items = Array.from(MessageV2.stream(session.id))
|
|
|
expect(items).toHaveLength(1)
|
|
|
expect(items[0].info.id).toBe(ids[0])
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -369,7 +390,7 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
await fill(session.id, 3)
|
|
|
|
|
|
const items = Array.from(MessageV2.stream(session.id))
|
|
|
@@ -378,7 +399,7 @@ describe("MessageV2.stream", () => {
|
|
|
expect(item.parts[0].type).toBe("text")
|
|
|
}
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -387,7 +408,7 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 60)
|
|
|
|
|
|
const items = Array.from(MessageV2.stream(session.id))
|
|
|
@@ -395,7 +416,7 @@ describe("MessageV2.stream", () => {
|
|
|
expect(items[0].info.id).toBe(ids[ids.length - 1])
|
|
|
expect(items[59].info.id).toBe(ids[0])
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -404,7 +425,7 @@ describe("MessageV2.stream", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
await fill(session.id, 1)
|
|
|
|
|
|
const gen = MessageV2.stream(session.id)
|
|
|
@@ -414,7 +435,7 @@ describe("MessageV2.stream", () => {
|
|
|
expect(first).toHaveProperty("done")
|
|
|
expect(first.done).toBe(false)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -425,7 +446,7 @@ describe("MessageV2.parts", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
const result = MessageV2.parts(id)
|
|
|
@@ -433,7 +454,7 @@ describe("MessageV2.parts", () => {
|
|
|
expect(result[0].type).toBe("text")
|
|
|
expect((result[0] as MessageV2.TextPart).text).toBe("m0")
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -442,13 +463,13 @@ describe("MessageV2.parts", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const id = await addUser(session.id)
|
|
|
|
|
|
const result = MessageV2.parts(id)
|
|
|
expect(result).toEqual([])
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -457,17 +478,17 @@ describe("MessageV2.parts", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: id,
|
|
|
type: "text",
|
|
|
text: "second",
|
|
|
})
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: id,
|
|
|
@@ -481,7 +502,7 @@ describe("MessageV2.parts", () => {
|
|
|
expect((result[1] as MessageV2.TextPart).text).toBe("second")
|
|
|
expect((result[2] as MessageV2.TextPart).text).toBe("third")
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -490,7 +511,7 @@ describe("MessageV2.parts", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- await Session.create({})
|
|
|
+ await svc.create({})
|
|
|
const result = MessageV2.parts(MessageID.ascending())
|
|
|
expect(result).toEqual([])
|
|
|
},
|
|
|
@@ -501,14 +522,14 @@ describe("MessageV2.parts", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
const result = MessageV2.parts(id)
|
|
|
expect(result[0].sessionID).toBe(session.id)
|
|
|
expect(result[0].messageID).toBe(id)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -519,7 +540,7 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
const result = MessageV2.get({ sessionID: session.id, messageID: id })
|
|
|
@@ -529,7 +550,7 @@ describe("MessageV2.get", () => {
|
|
|
expect(result.parts).toHaveLength(1)
|
|
|
expect((result.parts[0] as MessageV2.TextPart).text).toBe("m0")
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -538,13 +559,13 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
expect(() => MessageV2.get({ sessionID: session.id, messageID: MessageID.ascending() })).toThrow(
|
|
|
"NotFoundError",
|
|
|
)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -553,16 +574,16 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const a = await Session.create({})
|
|
|
- const b = await Session.create({})
|
|
|
+ const a = await svc.create({})
|
|
|
+ const b = await svc.create({})
|
|
|
const [id] = await fill(a.id, 1)
|
|
|
|
|
|
expect(() => MessageV2.get({ sessionID: b.id, messageID: id })).toThrow("NotFoundError")
|
|
|
const result = MessageV2.get({ sessionID: a.id, messageID: id })
|
|
|
expect(result.info.id).toBe(id)
|
|
|
|
|
|
- await Session.remove(a.id)
|
|
|
- await Session.remove(b.id)
|
|
|
+ await svc.remove(a.id)
|
|
|
+ await svc.remove(b.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -571,10 +592,10 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: id,
|
|
|
@@ -585,7 +606,7 @@ describe("MessageV2.get", () => {
|
|
|
const result = MessageV2.get({ sessionID: session.id, messageID: id })
|
|
|
expect(result.parts).toHaveLength(2)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -594,11 +615,11 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const uid = await addUser(session.id, "hello")
|
|
|
const aid = await addAssistant(session.id, uid)
|
|
|
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: aid,
|
|
|
@@ -611,7 +632,7 @@ describe("MessageV2.get", () => {
|
|
|
expect(result.parts).toHaveLength(1)
|
|
|
expect((result.parts[0] as MessageV2.TextPart).text).toBe("response")
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -620,14 +641,14 @@ describe("MessageV2.get", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const id = await addUser(session.id)
|
|
|
|
|
|
const result = MessageV2.get({ sessionID: session.id, messageID: id })
|
|
|
expect(result.info.id).toBe(id)
|
|
|
expect(result.parts).toEqual([])
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -638,7 +659,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 5)
|
|
|
|
|
|
const result = MessageV2.filterCompacted(MessageV2.stream(session.id))
|
|
|
@@ -646,7 +667,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
// reversed from newest-first to chronological
|
|
|
expect(result.map((item) => item.info.id)).toEqual(ids)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -655,13 +676,13 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
// Chronological: u1(+compaction part), a1(summary, parentID=u1), u2, a2
|
|
|
// Stream (newest first): a2, u2, a1(adds u1 to completed), u1(in completed + compaction) -> break
|
|
|
const u1 = await addUser(session.id, "first question")
|
|
|
const a1 = await addAssistant(session.id, u1, { summary: true, finish: "end_turn" })
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: a1,
|
|
|
@@ -672,7 +693,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
|
|
|
const u2 = await addUser(session.id, "new question")
|
|
|
const a2 = await addAssistant(session.id, u2)
|
|
|
- await Session.updatePart({
|
|
|
+ await svc.updatePart({
|
|
|
id: PartID.ascending(),
|
|
|
sessionID: session.id,
|
|
|
messageID: a2,
|
|
|
@@ -685,7 +706,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
expect(result[0].info.id).toBe(u1)
|
|
|
expect(result.length).toBe(4)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -699,7 +720,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
const u1 = await addUser(session.id, "hello")
|
|
|
await addCompactionPart(session.id, u1)
|
|
|
@@ -708,7 +729,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
const result = MessageV2.filterCompacted(MessageV2.stream(session.id))
|
|
|
expect(result).toHaveLength(2)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -717,7 +738,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
const u1 = await addUser(session.id, "hello")
|
|
|
await addCompactionPart(session.id, u1)
|
|
|
@@ -733,7 +754,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
// Error assistant doesn't add to completed, so compaction boundary never triggers
|
|
|
expect(result).toHaveLength(3)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -742,7 +763,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
|
|
|
const u1 = await addUser(session.id, "hello")
|
|
|
await addCompactionPart(session.id, u1)
|
|
|
@@ -754,7 +775,7 @@ describe("MessageV2.filterCompacted", () => {
|
|
|
const result = MessageV2.filterCompacted(MessageV2.stream(session.id))
|
|
|
expect(result).toHaveLength(3)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -808,7 +829,7 @@ describe("MessageV2 consistency", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
await fill(session.id, 3)
|
|
|
|
|
|
const paged = MessageV2.page({ sessionID: session.id, limit: 10 })
|
|
|
@@ -818,7 +839,7 @@ describe("MessageV2 consistency", () => {
|
|
|
expect(got.parts).toEqual(item.parts)
|
|
|
}
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -827,14 +848,14 @@ describe("MessageV2 consistency", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const [id] = await fill(session.id, 1)
|
|
|
|
|
|
const got = MessageV2.get({ sessionID: session.id, messageID: id })
|
|
|
const standalone = MessageV2.parts(id)
|
|
|
expect(got.parts).toEqual(standalone)
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -843,7 +864,7 @@ describe("MessageV2 consistency", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
await fill(session.id, 7)
|
|
|
|
|
|
const streamed = Array.from(MessageV2.stream(session.id))
|
|
|
@@ -861,7 +882,7 @@ describe("MessageV2 consistency", () => {
|
|
|
|
|
|
expect(streamed.map((m) => m.info.id)).toEqual(paged.map((m) => m.info.id))
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
@@ -870,7 +891,7 @@ describe("MessageV2 consistency", () => {
|
|
|
await Instance.provide({
|
|
|
directory: root,
|
|
|
fn: async () => {
|
|
|
- const session = await Session.create({})
|
|
|
+ const session = await svc.create({})
|
|
|
const ids = await fill(session.id, 4)
|
|
|
|
|
|
const filtered = MessageV2.filterCompacted(MessageV2.stream(session.id))
|
|
|
@@ -878,7 +899,7 @@ describe("MessageV2 consistency", () => {
|
|
|
|
|
|
expect(filtered.map((m) => m.info.id)).toEqual(all.map((m) => m.info.id))
|
|
|
|
|
|
- await Session.remove(session.id)
|
|
|
+ await svc.remove(session.id)
|
|
|
},
|
|
|
})
|
|
|
})
|