MCPcopy Create free account
hub / github.com/cortexkit/magic-context / persistPiMessageEndModelMeta

Function persistPiMessageEndModelMeta

packages/pi-plugin/src/index.ts:156–184  ·  view source on GitHub ↗
(args: {
	db: ContextDatabase;
	sessionId: string;
	message: unknown;
	cacheTtlConfig: MagicContextConfig["cache_ttl"];
})

Source from the content-addressed store, hash-verified

154}
155
156export function persistPiMessageEndModelMeta(args: {
157 db: ContextDatabase;
158 sessionId: string;
159 message: unknown;
160 cacheTtlConfig: MagicContextConfig["cache_ttl"];
161}): void {
162 if (!args.message || typeof args.message !== "object") return;
163 const msg = args.message as {
164 role?: string;
165 provider?: string;
166 model?: string;
167 };
168 if (
169 msg.role !== "assistant" ||
170 typeof msg.provider !== "string" ||
171 msg.provider.length === 0 ||
172 typeof msg.model !== "string" ||
173 msg.model.length === 0
174 ) {
175 return;
176 }
177 const modelKey = `${msg.provider}/${msg.model}`;
178 recordPiLiveModel(args.sessionId, modelKey);
179 const cacheTtl = resolveCacheTtl(args.cacheTtlConfig, modelKey);
180 const currentMeta = getOrCreateSessionMeta(args.db, args.sessionId);
181 if (currentMeta.cacheTtl !== cacheTtl) {
182 updateSessionMeta(args.db, args.sessionId, { cacheTtl });
183 }
184}
185
186function info(message: string, data?: unknown): void {
187 log(`${PREFIX} ${message}`, data);

Callers 2

index.tsFile · 0.85

Calls 4

recordPiLiveModelFunction · 0.90
resolveCacheTtlFunction · 0.90
getOrCreateSessionMetaFunction · 0.90
updateSessionMetaFunction · 0.90

Tested by

no test coverage detected