(args: {
db: ContextDatabase;
sessionId: string;
message: unknown;
cacheTtlConfig: MagicContextConfig["cache_ttl"];
})
| 154 | } |
| 155 | |
| 156 | export 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 | |
| 186 | function info(message: string, data?: unknown): void { |
| 187 | log(`${PREFIX} ${message}`, data); |
no test coverage detected