summaryrefslogtreecommitdiffhomepage
path: root/packages/conversation-store/src/extension.ts
blob: cd0307717023ad79aa393b449c4d2b654deb5944 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { Extension, HostAPI, Manifest } from "@dispatch/kernel";
import { conversationStoreHandle, createConversationStore } from "./store.js";

export const manifest: Manifest = {
	id: "conversation-store",
	name: "Conversation Store",
	version: "0.0.0",
	apiVersion: "^0.1.0",
	trust: "bundled",
	capabilities: { db: true },
	contributes: { services: ["conversation-store/store"] },
	activation: "eager",
};

export const extension: Extension = {
	manifest,
	activate: async (host: HostAPI) => {
		const storage = host.storage("conversation-store");
		const store = createConversationStore(storage, host.logger, undefined, process.cwd());

		const stale = await store.listConversations({ status: ["active"] });
		for (const m of stale) {
			await store.setConversationStatus(m.id, "idle");
		}
		if (stale.length > 0) {
			host.logger.info("conversation-store: boot-sweep", { resetCount: stale.length });
		}

		host.provideService(conversationStoreHandle, store);
	},
};